用GDB 调试system_monitor

Easy debug with GDB, step by step.

Debug process:                                 system_monitor

Debug platform:               Riogrande, Lotus

 

1.       Build lotus eng or debug version

1)      Remove the followings in device/semc/riogrande/files/init.riogrande.rc

# SEMC System monitor

#service system_monitor /system/bin/system_monitor

#    user root

2)      For not running system_monitor as service

2.       Flash the sins into mobile phone

3.       Setup GDB environment

1)      sudo apt-get install semc-gdb-arm semc-python-gdb

2)      https://wiki.sonyericsson.net/androiki/GDB_debugging

3)      https://wiki.sonyericsson.net/mib/GDB_Tool_Course

4.       Open two terminal windows, one for gdbclient, another for gdbserver

5.       In one terminal window for gdbserver

1)      $adb remount

2)      $adb push gdbserver73 /system/bin/gdbserver        //gdbserver73 is the enclosure.

3)      $adb shell

4)      #chmod 777 /system/bin/gdbserver

5)      # gdbserver :5039 /system/bin/system_monitor

Show the following infomation

Process /system/bin/system_monitor created; pid = 2678

Listening on port 5039

 

Remote debugging from host 127.0.0.1                                 //later show the information after gdbclient runs

6.       In another terminal window for gdbclient

1)      Firstly, enter the root directory of edream6.0-riogrande-xxx  source  code

For example: xx@xx: /…./edream6.0-riogrande-plus-release$

2)      xx@xx: /…./edream6.0-riogrande-plus-release$. build/envsetup.sh

3)      xx@xx: /…./edream6.0-riogrande-plus-release$lunch lotus-eng   or lunch lotus-userdebug

4)      xx@xx: /…./edream6.0-riogrande-plus-release$adb forward tcp:5039 tcp:5039

5)      xx@xx: /…./edream6.0-riogrande-plus-release$setpaths

6)      xx@xx: /…./edream6.0-riogrande-plus-release$ gdbclient system_monitor

Show the following information:

If you haven't done so already, do this first on the device:

    gdbserver :5039 /system/bin/system_monitor

or

   gdbserver :5039 --attach

 

GNU gdb (GDB) 7.1-android-gg2

Copyright (C) 2010 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 "--host=x86_64-linux-gnu --target=arm-elf-linux".

For bug reporting instructions, please see:

<http://www.gnu.org/software/gdb/bugs/>...

Reading symbols from /media/Disk1T/CodeResources/Lotus/edream6.0-riogrande-plus-release/out/target/product/lotus/symbols/system/bin/system_monitor...done.

BFD: /media/Disk1T/CodeResources/Lotus/edream6.0-riogrande-plus-release/out/target/product/lotus/symbols/system/bin/linker: warning: sh_link not set for section `.ARM.exidx'

BFD: /media/Disk1T/CodeResources/Lotus/edream6.0-riogrande-plus-release/out/target/product/lotus/symbols/system/bin/linker: warning: sh_link not set for section `.ARM.exidx'

__dl__start () at bionic/linker/arch/arm/begin.S:35

35                           mov       r0, sp

(gdb)

7)      (gdb)info break   //show all breakpoints information

No breakpoints or watchpoints.

8)      (gdb) b sysmon.c:main  //set breakpoint on the main function of sysmon.c

Breakpoint 1 at 0xba54: file vendor/semc/hardware/sysmon/sysmon.c, line 279.

9)      (gdb) c  //continue to run the process of system_monitor

Continuing.

 

Breakpoint 1, main (argc=1, argv=0xbef0abc4) at vendor/semc/hardware/sysmon/sysmon.c:279

279                         int ret = 0;

10)   (gdb) bt                                //show the call stack

#0  main (argc=1, argv=0xbef0abc4) at vendor/semc/hardware/sysmon/sysmon.c:279

11)   (gdb) info args   //show Argument variables of current stack frame

argc = 1

argv = 0xbef0abc4

12)   (gdb) n                 //Next line. Overstepping the function

281                         if (!td) {

13)   (gdb) info locals                //show Local variables of current stack frame

ret = 0

__PRETTY_FUNCTION__ = "main"

14)   (gdb) l                   // List specified function or line.

276        

277         int main(int argc, char **argv)

278         {

279                         int ret = 0;

280        

281                         if (!td) {

282                                         LOGE("%s - Local data structure not allocated\n", __func__);

283                                         return -ENOMEM;

284                         }

285        

15)   (gdb) print td     // Print value of expression EXP

$1 = (struct sysmon *) 0xf028

16)   (gdb) ptype td   // Print definition of type TYPE.

type = struct sysmon {

    char *plugin_path;

    char *config_file;

    char *socket_path;

    pthread_mutex_t lock;

    int num_socket_clients;

} *

17)   (gdb) print td.plugin_path           //Print someone value in the td struct

$2 = 0xf040 "/system/lib/sysmon/"

18)   (gdb) list parse_options                                // List specified function or line.

236        

237                         flags |= PRINT_DONE;

238         }

239        

240         static int parse_options(int argc, char **argv, struct sysmon *td)

241         {

242                         int opt;

243                         const char *opts = "c:p:s:n:hla";

244        

245                         while ((opt = getopt(argc, argv, opts)) != -1) {

19)   (gdb) break 245                                // set breakpoint on the line 245

Breakpoint 2 at 0xb904: file vendor/semc/hardware/sysmon/sysmon.c, line 245.

20)   (gdb) info break                               //show all breakpoints information

Num     Type           Disp Enb Address    What

1       breakpoint     keep y   0x0000ba54 in main at vendor/semc/hardware/sysmon/sysmon.c:279

                breakpoint already hit 1 time

2       breakpoint     keep y   0x0000b904 in parse_options at vendor/semc/hardware/sysmon/sysmon.c:245

21)   (gdb) delete 1                   //delete the breakpoint whose Num is 1

(gdb) info break

Num     Type           Disp Enb Address    What

2       breakpoint     keep y   0x0000b904 in parse_options at vendor/semc/hardware/sysmon/sysmon.c:245

22)   (gdb) c                                  //Continue execution

Continuing.

 

Breakpoint 2, parse_options (argc=1, argv=0xbef0abc4, td=0xf028) at vendor/semc/hardware/sysmon/sysmon.c:245

245                         while ((opt = getopt(argc, argv, opts)) != -1) {

23)   (gdb) print argc                 // Print value of expression EXP

$4 = 1

(gdb) print argv

$5 = (char **) 0xbef0abc4

(gdb) print argv[0]

$6 = 0xbef0acb3 "/system/bin/system_monitor"

(gdb) print opts

$7 = 0xcea8 "c:p:s:n:hla"

24)   (gdb) n                 //next line. Overstepping the function

//I don’t know why there is error?

Program received signal SIGSEGV, Segmentation fault.

0x00008d30 in ?? ()

25)   Restart gdbserver and gdbclient

(gdb) break sysmon.c:parse_options

Breakpoint 1 at 0xb8fe: file vendor/semc/hardware/sysmon/sysmon.c, line 243.

(gdb) c

Continuing.

 

Breakpoint 1, parse_options (argc=1, argv=0xbe936bc4, td=0xf028) at vendor/semc/hardware/sysmon/sysmon.c:243

243                         const char *opts = "c:p:s:n:hla";

(gdb) l

238         }

239        

240         static int parse_options(int argc, char **argv, struct sysmon *td)

241         {

242                         int opt;

243                         const char *opts = "c:p:s:n:hla";

244        

245                         while ((opt = getopt(argc, argv, opts)) != -1) {

246                                         switch (opt) {

247                                         case 'c':

(gdb) l

248                                                         free(td->config_file);

249                                                         td->config_file = strdup(optarg);

250                                                         break;

251                                         case 'p':

252                                                         free(td->plugin_path);

253                                                         td->plugin_path = strdup(optarg);

254                                                         break;

255                                         case 's':

256                                                         free(td->socket_path);

257                                                         td->socket_path = strdup(optarg);

(gdb) l

258                                                         break;

259                                         case 'n':

260                                                         td->num_socket_clients = atoi(optarg);

261                                                         break;

262                                         case 'l':

263                                                         flags |= PRINT_SENSORS;

264                                                         break;

265                                         case 'a':

266                                                         flags |= PRINT_ACTIONS;

267                                                         break;

(gdb) l

268                                         case 'h':

269                                         default:

270                                                         print_usage();

271                                                         return -EINVAL;

272                                         }

273                         }

274                         return 0;

275         }

276        

277         int main(int argc, char **argv)

26)   (gdb) break 274

Breakpoint 2 at 0xba22: file vendor/semc/hardware/sysmon/sysmon.c, line 274.

27)   (gdb) c

Continuing.

 

Breakpoint 2, parse_options (argc=1, argv=0xbe936bc4, td=0xf028) at vendor/semc/hardware/sysmon/sysmon.c:274

274                         return 0;

28)   (gdb) info locals                                // Show Local variables of current stack frame

opt = -1

opts = 0xcea8 "c:p:s:n:hla"

29)   (gdb) print opt

$1 = -1

30)   (gdb) n

275         }

31)   (gdb)

main (argc=1, argv=0xbe936bc4) at vendor/semc/hardware/sysmon/sysmon.c:287

287                         if (ret) {

32)   (gdb) n                

//I don’t know why this happens?

Stopped due to shared library event

33)   (gdb)

notify_gdb_of_load (info=0xb0009f48) at bionic/linker/linker.c:230

230             insert_soinfo_into_debug_map(info);

34)   (gdb) return       // Make selected stack frame return to its caller

Make notify_gdb_of_load return now? (y or n) y

35)   It is no useful, Restart gdbserver and gdbclient

36)   (gdb) break sysmon.c:292

Breakpoint 1 at 0xbab6: file vendor/semc/hardware/sysmon/sysmon.c, line 292.

37)   (gdb) c

Continuing.

 

Breakpoint 1, main (argc=1, argv=0xbeba0bc4) at vendor/semc/hardware/sysmon/sysmon.c:292

292                         ret = load_plugins(td);

38)   (gdb) n                 //I don’t know why share lib cannot be mapped

Error while mapping shared library sections:

sysmon_ab8500.so: No such file or directory.

Error while mapping shared library sections:

sysmon_ab8500_bat_ctrl.so: No such file or directory.

Error while mapping shared library sections:

sysmon_ab8500_bat_temp.so: No such file or directory.

Error while mapping shared library sections:

sysmon_ab8500_ext_rtc_xtal.so: No such file or directory.

Error while mapping shared library sections:

sysmon_db8500.so: No such file or directory.

Error while mapping shared library sections:

sysmon_db8500_ext.so: No such file or directory.

Error while mapping shared library sections:

sysmon_lcd_brightness_reset.so: No such file or directory.

Error while mapping shared library sections:

sysmon_lcd_brightnesslevel30.so: No such file or directory.

Error while mapping shared library sections:

sysmon_lcd_brightnesslevel50.so: No such file or directory.

Error while mapping shared library sections:

sysmon_lcd_brightnesslevel70.so: No such file or directory.

Error while mapping shared library sections:

sysmon_test_sensor.so: No such file or directory.

293                         if (ret) {

39)   (gdb) n

298                         if (flags & PRINT_SENSORS)

40)   (gdb) n

300                         if (flags & PRINT_ACTIONS)

41)   (gdb)                     //directly enter

302                         if (flags & PRINT_DONE)

42)   (gdb)                     //directly enter

//Why this happens?

Program received signal SIGILL, Illegal instruction.

0x0000bb1e in main (argc=1, argv=0xbeb35bc4) at vendor/semc/hardware/sysmon/sysmon.c:302

302                         if (flags & PRINT_DONE)

43)   Restart gdbserver and gdbclient

44)   (gdb) break sysmon.c:286

Breakpoint 1 at 0xba82: file vendor/semc/hardware/sysmon/sysmon.c, line 286.

45)   (gdb) c

Continuing.

 

Breakpoint 1, main (argc=1, argv=0xbe984bc4) at vendor/semc/hardware/sysmon/sysmon.c:286

286                         ret = parse_options(argc, argv, td);

46)   (gdb) s                  // Step program until it reaches a different source line.

//Why this happens?

Program received signal SIGILL, Illegal instruction.

0x0000ba8c in main (argc=1, argv=0xbe984bc4) at vendor/semc/hardware/sysmon/sysmon.c:286

286                         ret = parse_options(argc, argv, td);

47)   Test over

 

7.       Conclusion

1)      GDB can debug process in user space, step by step.

2)      It is not always stable,  special for commands step into function, next over function. It is easy to happen error.  I don’t know why?

3)      But we can set more breakpoints and use command “continue”, it seems not to happen error.

4)      Anyway, you can get help of how to use gdb commands by “(gdb)help command”, such as “(gdb)help info”

8.       Question

1)      What’s your comments about errors often happen in the debug process?

2)      Is there another more advantage tool for debug program in user side?

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值