通过gdb可以方便的连接到qemu虚拟机调试内核,但是调试命令中如果有字符串参数的话,命令无法执行
>>> p boot_command_line $3 = 0x8094f014 <boot_command_line> "loglevel=0 root=/dev/mmcblk0 console=ttyAMA0" >>> call strcmp("good",boot_command_line) evaluation of this expression requires the program to have a function "malloc". >>> find boot_command_line,+0x100,{char[7]}"console" A syntax error in expression, near `sizeof("console"]}"console"'.
原因是gdb需要被调试的“程序”实现malloc函数,即kenerl要实现malloc函数。但是内核下分配内存使用的是kmalloc,并没有实现malloc,因此无法执行此类命令
基于这个原因,我撰写了一个基于全局数组的malloc函数实现,编译仅内核即可让gdb支持传递字符串参数。