2

I wanted to know what an API is returning in a kernel module < vnos-module.ko>.

Go to know from few forms that it is not that straight forward, we need to load the symbol table to debug a kernel module.

So all I did is, 1. tried to find .text .bss and .data section address of the kernel module. 2. Add symbol table file using add-symbol-file command in gdb.

But I get error saying "Reading symbols from /fabos/modules/vnos-module.ko...(no debugging symbols found)...done."

is there anything I am missing here?

root@sw0:/sys/module/vnos_module/sections# cat .text .data .bss 
0xf7f7f000
0xf7fb7a30
0xf7fc3da4

root@sw0:/sys/module/vnos_module/sections# gdb /fabos/modules/vnos-module.ko
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /fabos/modules/vnos-module.ko...(no debugging symbols found)...done.
 add-symbol-file /fabos/modules/vnos-module.ko 0xf7f7f000 -s .data 0xf7fb7a -s .bss 0xf7fc3da4
add symbol table from file "/fabos/modules/vnos-module.ko" at
        .text_addr = 0xf7f7f000
        .data_addr = 0xf7fb7a30
(y or n) y

Reading symbols from /fabos/modules/vnos-module.ko...(no debugging symbols found)...done.

Please help.

valiano
  • 16,433
  • 7
  • 64
  • 79
shim_mang
  • 323
  • 4
  • 17
  • 1
    if the file has no symbols, it has no symbols: you cannot debug, even if you know the addresses of the sections. You have to get a file with symbols or a separate symbol file corresponding to your binary. – Jean-François Fabre Jul 18 '16 at 07:48
  • Is there any way to compile the module to incorporate symbols? – shim_mang Jul 18 '16 at 12:35

1 Answers1

2

Since I can't comment I'll write as an answer. (but I know it's more of a comment section post since I'm not 100% sure about it)

You have to compile your module with debugging symbols. In order to do so module should be compiled without stripping. You might also want to try -g option and to have debugging enabled in your kernel CONFIG_DEBUG_INFO=y.

Not sure if it'll work.

RoughTomato
  • 405
  • 7
  • 16
  • Thanks, I will try. – shim_mang Jul 19 '16 at 10:36
  • Yes, this worked for me.Also I wanted to know an API returns? Just giving "gdb vnos-module.ko" and then "run" will not work out. I get a permission issue. – shim_mang Jul 19 '16 at 11:16
  • 1
    your gdb seems to be requiring root permission to debug. [Here](http://stackoverflow.com/questions/25586972/why-is-gdb-requiring-root-permission-to-debug-user-programs) somebody had similar issue. I don't quite understand what you mean by "API returns" (but it's early in the morning where I live so that might be the case), if you explain it to me I'll try to help my best. – RoughTomato Jul 20 '16 at 06:31
  • Thanks for the link. But the problem is quite different. I want to do live debugging of kernel module. That is what I meant when I said I want to know what an API returns. And with -g compiler flag < debug flag> in the makefile of the module helped me to get the symbol table being added automatically with disadvantage of kernel module size being increased though. – shim_mang Jul 21 '16 at 07:10
  • 1
    "with disadvantage of kernel module size being increased though." treat it as debugg (development version) and release (striped version). That seems to be usual trend in development from my experience. Did you set up brakepoints? you can also go line by line through the file. Does gdb even respect your brakepoints? (I had a situation once when it didn't) – RoughTomato Jul 21 '16 at 07:39
  • Yes I agree. I do had set the breakpoints. But "run"ning the module (.ko) is not allowed. It throws me error saying "permission denied". I don't think the problem is with the permission but the input I have given to gdb, I mean .ko module, is what I doubting about. Is it allowed to RUN a kernel module? – shim_mang Jul 21 '16 at 11:15
  • I'll try to recreate your problem when I find some spare time, unfortunately had a lot to do at work today. Sorry. I don't think that's normal permissions related in like chmod sense. GDB probably expects to run in user space instead it gets denied by kernel space, because you can't give yourself permission to go to kernel space. Although I believe it's possible somehow. I'll keep digging. – RoughTomato Jul 22 '16 at 13:44
  • Sure, I am still in search of a solution for my problem – shim_mang Jul 29 '16 at 09:41
  • Unfortunately I'm somewhat unable to recreate problem for myself. Do you have CONFIG_DEBUG_INFO flag enabled in your kernel? – RoughTomato Jul 29 '16 at 09:46
  • Yes. My problem now, I am able to load all the symbols and read them. But I am not able to "run" the kernel module. I doubt we can do that. If not, then need an alternative. – shim_mang Jul 29 '16 at 09:48
  • Usually at work I write debug information by hand using defines, creating macros and logging mechanisms. It's not as reliant method but it's better than nothing. I'm pretty sure there is some way to use gdb for kernel modules debugging although I can't remember doing it myself. I usually use gdb server for userspace stuff. – RoughTomato Jul 29 '16 at 09:54
  • http://stackoverflow.com/questions/11408041/how-to-debug-the-linux-kernel-with-gdb-and-qemu?rq=1 maybe that'll be of a little help. – RoughTomato Jul 29 '16 at 11:03