debug module .ko

When

cat /sys/module/hellotest/sections/.text = 0x00000000

Try this way

gedit /root/project_board/free_imx/myandroid/kernel_imx/kernel/module.c

//in function load_module(struct load_info *info, const char __user *uargs, int flags)

//after

err = post_relocation(mod, info);

//add

printk(KERN_WARNING “.ko name=%s coreaddr=%x\n”, mod->name, mod->module_core);

[mod->module_core] will apply to add-symbol-file later

root@matrix_io:/ # insmod /data/hellomod/hellotest.ko

[ 590.764322] .ko name=hellotest coreaddr=7f11c000

in eclipse right click your project

Debug As → Debug Configurations → GDB Hardware Debugging

click [Startup tab]

uncheck the all items on startup page

add those lines under [Halt] box but do not check [Halt]

add-symbol-file /root/project_board/free_imx/out/matrix_io/uboot/u-boot 0x7f11c000

then click [Apply]

It’s the global variable problem

kptr_restrict

another way to cat .text

modify module_sect_show() in module.c

→ return sprintf(buf, “0x%p\n”, (void *)sattr->address) /*sprintf(buf, “0x%pK\n”, (void )sattr->address)/;

cat /sys/module/hellotest/sections/.text

root@matrix_io:/ # insmod /data/hellomod/hellotest.ko

[ 139.012925] .ko name=hellotest / coreaddr=0x7f11c000

[ 139.019392] Hello, world

root@matrix_io:/ # cat /sys/module/hellotest/sections/.text

0x7f11c000

demo photo:

https://picasaweb.google.com/1061855410 … 4292643346

i use watchpoint trace to ptr_restrict, who write it

in /root/project_board/free_imx/myandroid/kernel_imx/kernel/sysctl.c

do_proc_dointvec_minmax_conv

*valp = val; —> here to write~~~~ valp is &ptr_restrict

demo:

https://picasaweb.google.com/1061855410 … 0623335890

in device/fsl/matrix/etc/init.rc

write /proc/sys/kernel/kptr_restrict 2

to

write /proc/sys/kernel/kptr_restrict 0