我在 C 中的变量声明时遇到了一些麻烦,希望您能帮助我。
这段代码:
int makeDir(const char* path, mode_t mode) {
printf("Checkpoint 1\n");
String parentPath;
printf("Checkpoint 2\n");
pDirTreeNode parent;
printf("Checkpoint 3\n");
int idx, grp;
pinode inod;
pdir algo=NULL;
printf("Checkpoint 4\n");
pdir direntry=NULL;
printf("Checkpoint 5\n");
t_bitarray *bitarr;
parent = malloc(sizeof(struct dirTreeNode));
parentPath = malloc(DIR_NAME_SIZE);
direntry=malloc(sizeof(struct s_direct));
[COMMENTED code]
}
这些是数据类型声明:
typedef struct s_inode *pinode;
typedef struct s_direct *pdir;
typedef char *String;
typedef struct dirTreeNode *pDirTreeNode;
在 linux/ext2_fs.h 头文件中声明了 s_inode 和 s_direct
我已经执行了它,当程序到达它提示的功能时:
由于共享库事件/build/buildd/gdb-7.3/gdb/dwarf2loc.c:185:内部错误:dwarf_expr_frame_base:断言“framefunc!= NULL”失败。已检测到 GDB 内部的问题,进一步调试可能证明不可靠。
但它不会停止调试会话。然后,如果我执行其余代码:
*** glibc detected *** /home/vlad/workspace_SisOp/RFSDev/Debug/RFSDev: realloc(): invalid next size: 0x0000000000a5cdf0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7a6e6)[0x7fa21d6e26e6]
/lib/x86_64-linux-gnu/libc.so.6(+0x7d3e7)[0x7fa21d6e53e7]
/lib/x86_64-linux-gnu/libc.so.6(realloc+0xf9)[0x7fa21d6e6b39]
/home/vlad/workspace_SisOp/RFSDev/Debug/RFSDev[0x402cd3]
/home/vlad/workspace_SisOp/RFSDev/Debug/RFSDev[0x4017a4]
/home/vlad/workspace_SisOp/RFSDev/Debug/RFSDev[0x400af7]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xed)[0x7fa21d68930d]
/home/vlad/workspace_SisOp/RFSDev/Debug/RFSDev[0x4009e9]
======= Memory map: ========
00400000-00404000 r-xp 00000000 00:14 540784 /home/vlad/workspace_SisOp/RFSDev/Debug/RFSDev
00603000-00604000 r--p 00003000 00:14 540784 /home/vlad/workspace_SisOp/RFSDev/Debug/RFSDev
00604000-00605000 rw-p 00004000 00:14 540784 /home/vlad/workspace_SisOp/RFSDev/Debug/RFSDev
00a5c000-00a7d000 rw-p 00000000 00:00 0 [heap]
7fa214000000-7fa214021000 rw-p 00000000 00:00 0
7fa214021000-7fa218000000 ---p 00000000 00:00 0
7fa21b706000-7fa21b71b000 r-xp 00000000 08:16 526333 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa21b71b000-7fa21b91a000 ---p 00015000 08:16 526333 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa21b91a000-7fa21b91b000 r--p 00014000 08:16 526333 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa21b91b000-7fa21b91c000 rw-p 00015000 08:16 526333 /lib/x86_64-linux-gnu/libgcc_s.so.1
7fa21b91c000-7fa21d668000 rw-p 00000000 00:14 273074 /home/vlad/Sistemas Operativos/ext2.disk
7fa21d668000-7fa21d7ff000 r-xp 00000000 08:16 526221 /lib/x86_64-linux-gnu/libc-2.13.so
7fa21d7ff000-7fa21d9fe000 ---p 00197000 08:16 526221 /lib/x86_64-linux-gnu/libc-2.13.so
7fa21d9fe000-7fa21da02000 r--p 00196000 08:16 526221 /lib/x86_64-linux-gnu/libc-2.13.so
7fa21da02000-7fa21da03000 rw-p 0019a000 08:16 526221 /lib/x86_64-linux-gnu/libc-2.13.so
7fa21da03000-7fa21da09000 rw-p 00000000 00:00 0
7fa21da09000-7fa21da2a000 r-xp 00000000 08:16 523159 /lib/x86_64-linux-gnu/ld-2.13.so
7fa21dc10000-7fa21dc13000 rw-p 00000000 00:00 0
7fa21dc26000-7fa21dc29000 rw-p 00000000 00:00 0
7fa21dc29000-7fa21dc2a000 r--p 00020000 08:16 523159 /lib/x86_64-linux-gnu/ld-2.13.so
7fa21dc2a000-7fa21dc2c000 rw-p 00021000 08:16 523159 /lib/x86_64-linux-gnu/ld-2.13.so
7fff21b19000-7fff21b3a000 rw-p 00000000 00:00 0 [stack]
7fff21ba2000-7fff21ba3000 r-xp 00000000 00:00 0 [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]
Checkpoint 1
Checkpoint 2
Checkpoint 3
Checkpoint 4
Checkpoint 5
在调试会话中,代码实际上在 perror("1") 之后爆炸,所以看起来不仅仅是 perror 的问题......
提前致谢!
编辑:我更改了转储消息和函数代码以避免错误。此外,这是完整的主要代码:
pext2fs fsys; // Variable global
int main(int argv, char *argc[]) {
fsys = malloc(sizeof(struct ext2system));
getsysdata();
/* *
* *
* *
* File System Client here *
* *
* *
* */
/* ------------------>Código para probar funciones<------------------ */
pDirTreeNode node;
StringArray test;
void **file=malloc(0);
int ctrl, mode=0x1000;
pdir *dirents;
makeDir("\\Dir2\\DirCreadoInternamente", mode);
node = getDirTreeNode("\\Dir2\\DirCreadoInternamente");
// dirents = list_dir(fsys->root);
// node = getDirTreeNode("\\Dir3\\UnDir");
// ctrl = getFile(&file, "\\Dir1\\LPD");
// printFile(file);
/* ------------------>Fin del código de testing<------------------ */
unmap(fsys->diskmap);
return 0;
}