用GDB 调试system_monitor

来源:互联网 发布:郑州网络电视台直播 编辑:程序博客网 时间:2024/04/29 16:01

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                                // ShowLocal 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?

 

原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 海归落户过了两年期怎么办 借呗学历填错了怎么办 上海落户应届生分不够怎么办 应届生落户分数不够72分怎么办? 上海应届生落户时间延误怎么办 南京市区户口签江宁怎么办 深圳公司集体户口离职后怎么办 济南本地户口不符合入学条件怎么办 上海住亲戚家怎么办居住证 政府卖非农户口怎么办 90年代买了户口怎么办 上海应届大学生积分不够怎么办 广州居住证回执单丢了怎么办 惠阳居住证回执单丢了怎么办 南京居住证换地方了怎么办 买家退回的商品有问题怎么办 农转农户口手续怎么办 原房东不迁户口我怎么办 户主信息页掉了怎么办 户主变了户口本首页怎么办 大人户口迁走小孩户口怎么办 网银转账处理中怎么办 教育部学籍在线验证报告有错怎么办 验证码连续输入三次错误怎么办 交通运输监察大队截车了怎么办 平安安康续保没成功怎么办 危险品经营许可证到期了怎么办 郑万350渝万怎么办 厂里饭堂的饭好难吃怎么办 学校的食堂饭菜不好不卫生怎么办 亲戚借钱我真没有怎么办 榴莲肉酸了吃了怎么办 亲戚赖在家里住怎么办 食堂饭菜味道差该怎么办 被监视居住公安打电话睡着了怎么办 鱼缺氧浮上水面怎么办 车载低音炮有电流声怎么办 925纯银变黑了怎么办 银子放久了变黑怎么办 高铁票网上售空怎么办 高铁票出票失败怎么办