Working with GDB

Using gdb to user space program
vbhadra@ubuntu:~$ sudo gdb ./netlinkUser
[sudo] password for vbhadra:
GNU gdb (Ubuntu 7.9-1ubuntu1) 7.9
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <;

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 "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
Find the GDB manual and other documentation resources online at:
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./netlinkUser...done.

(gdb) b mlme_scan_validate_add_scan_req
Breakpoint 1 at 0x400fef: file netlinkUser.c, line 55.

(gdb) r
Starting program: /home/vbhadra/repos/java-linux3/drivers/scsc/drivers/misc/samsung/scsc/netlinkUser
[Thread debugging using libthread_db enabled]

[New Thread 0x7ffff72cc700 (LWP 2466)]
[Switching to Thread 0x7ffff72cc700 (LWP 2466)]

Breakpoint 1, mlme_scan_validate_add_scan_req (req=0x7ffff0005124)
at netlinkUser.c:55
55 debug(“requested scan_id = 0x%x\n”, req->scan_id);

(gdb) list
50 /*
51 * See description in mlme_scan/mlme_scan_param_set.h
52 *---------------------------------------------------------------------------*/
53 bool mlme_scan_validate_add_scan_req(const MlmeAddScan_request *req)
54 {
55 debug("requested scan_id = 0x%x\n", req->scan_id);
56 if ((req->common.source & PROCESSOR_HOST) == PROCESSOR_HOST) {
57 if (req->scan_id < MLME_SCAN_MIN_HOST_SCAN_ID) { 58 //fault(fault_mlme_scan, fault_scan_verification_scan_id_invalid); 59 log_err("scan verification: Invalid scan_id = 0x%x\n", req->scan_id);

To see the memory layout of a structure MlmeAddScan_request
1. Find out the size of the structure with sizeof
(gdb) p sizeof(MlmeAddScan_request)
$3 = 32

2. Check the address of the pointer pointing to the structure MlmeAddScan_request
Here the req pointer is pointing to the address of type MlmeAddScan_request.
(gdb) p req
$2 = (const MlmeAddScan_request *) 0x7ffff000a174

So 0x7ffff000a174 is the address of the structure MlmeAddScan_request in this case.

3. Use x command to see the memory layout
(gdb) x/32 0x7ffff000a174
0x7ffff000a174: 0x00000000 0x00000205 0x0000c00c 0x00000000
0x7ffff000a184: 0x00fa0100 0x000000fa 0x3322110f 0x00000000
0x7ffff000a194: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff000a1a4: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff000a1b4: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff000a1c4: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff000a1d4: 0x00000000 0x00000000 0x00000000 0x00000000
0x7ffff000a1e4: 0x00000000 0x00000000 0x00000000 0x00000000

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s