为GDB编写前端 [英] Writing Front End for GDB

查看:339
本文介绍了为GDB编写前端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写一个基于GDB的基于GUI的调试器。因为,我不希望节目在观看点或断点后停止。相反,它应该将文件名,行号,新值和内容等细节重定向到文件并继续执行。



我的脚本编写很糟糕。所以,我想要一些起点开始开发GDB的前端。据我搜索,这个链接 http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_node/gdb_211.html 对初学者来说并不是很理解这个活动?



希望我能在C / C ++中获得帮助。

解决方案

为了编写一个GDB前端,你确实需要使用 GDB / MI 协议,但也许阅读最新版本,而不是您链接到的较旧版本。



样本GDB / MI session



  $ gdb -q --interpreter = mi2 
=线程组添加,id =i1
(gdb)

文件/ bin / true

  -file-exec-and-symbols / bin / true 
^ done
(gdb)



中断主要

  -break-insert main 
^ done,bkpt = {number =1,type =breakpoint,disp =keep,enabled =y,addr =0x00000000004014c0,func =main ,FILE = true.c,全名= / usr / src目录/调试/的coreutils-8.17 / SRC / true.c,行= 59,时间= 0,原始位置= 主 }
(gdb)

运行和断点命中 p>

  -exec-run 
=线程组启动,id =i1,pid =2275
= thread-created,id =1,group-id =i1
^ running
* running,thread-id =all
(gdb)
= library-loaded,id =/ lib64 / ld-linux-x86-64.so.2,target-name =/ lib64 / ld-linux-x86-64.so.2,host-name = /lib64/ld-linux-x86-64.so.2\",symbols-loaded=\"0\",thread-gro up =i1
= library-loaded,id =/ lib64 / libc.so.6,target-name =/ lib64 / libc.so.6,host-name =/ lib64 / libc.so.6,symbols-loaded =0,thread-group =i1
=断点修改,bkpt = {number =1,type =breakpoint,disp =keep ,使能= Y,ADDR = 0x00000000004014c0 FUNC = 主,FILE = true.c,全名= / usr / src目录/调试/的coreutils-8.17 / SRC / true.c,线=59,times =1,original-location =main}
* stopped,reason =breakpoint-hit,disp =keep,bkptno =1,frame = {addr = 0x00000000004014c0 FUNC = 主,ARGS = [{名称= 的argc,值= 1},{名称= argv的,值= 0x7fffffffde98}],FILE = true.c ,全名= / usr / src目录/调试/的coreutils-8.17 / SRC / true.c,行= 59},线程ID = 1,停止线程= 所有,核心= 1
(gdb)

继续

  -exec-continue 
^ running
* running,thread-id =1
(gdb)
=线程退出,id =1,group-id =i1
=线程组退出,id =i1,退出代码=0
*停止,理由=退出 - 通常

退出GDB

 (gdb)
-gdb-退出
^退出



现有GDB / MI客户



C,C ++,Java,Python中有几个GDB / MI客户端实现。我会列举一些我觉得很容易阅读的内容:





您也可以浏览GDB前端的此列表


I want to write a GUI based debugger wrapped over GDB. Because, I dont want the program to stop after watch points or break points. Instead, it should redirect the details like filename, line number, new value and stuffs to a file and continue execution.

I am pretty bad at scripting. So, I want some starting point to start developing front end for GDB. As far as I googled, this link http://ftp.gnu.org/old-gnu/Manuals/gdb-5.1.1/html_node/gdb_211.html is not much understandable for a beginner in this activity?

Hopefully, I will get help on development in C/C++.

解决方案

For writing a GDB frontend, you indeed want to use the GDB/MI protocol but perhaps read this up-to-date copy instead of the older one you linked to.

Sample GDB/MI session

(Lightly edited version of this section from the GDB manual)

Launching GDB with the MI Command Interpreter

$ gdb -q --interpreter=mi2
=thread-group-added,id="i1"
(gdb)

File /bin/true

-file-exec-and-symbols /bin/true
^done
(gdb) 

Break main

-break-insert main
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x00000000004014c0",func="main",file="true.c",fullname="/usr/src/debug/coreutils-8.17/src/true.c",line="59",times="0",original-location="main"}
(gdb) 

Run and Breakpoint Hit

-exec-run
=thread-group-started,id="i1",pid="2275"
=thread-created,id="1",group-id="i1"
^running
*running,thread-id="all"
(gdb) 
=library-loaded,id="/lib64/ld-linux-x86-64.so.2",target-name="/lib64/ld-linux-x86-64.so.2",host-name="/lib64/ld-linux-x86-64.so.2",symbols-loaded="0",thread-group="i1"
=library-loaded,id="/lib64/libc.so.6",target-name="/lib64/libc.so.6",host-name="/lib64/libc.so.6",symbols-loaded="0",thread-group="i1"
=breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x00000000004014c0",func="main",file="true.c",fullname="/usr/src/debug/coreutils-8.17/src/true.c",line="59",times="1",original-location="main"}
*stopped,reason="breakpoint-hit",disp="keep",bkptno="1",frame={addr="0x00000000004014c0",func="main",args=[{name="argc",value="1"},{name="argv",value="0x7fffffffde98"}],file="true.c",fullname="/usr/src/debug/coreutils-8.17/src/true.c",line="59"},thread-id="1",stopped-threads="all",core="1"
(gdb) 

Continue

-exec-continue
^running
*running,thread-id="1"
(gdb) 
=thread-exited,id="1",group-id="i1"
=thread-group-exited,id="i1",exit-code="0"
*stopped,reason="exited-normally"

Quitting GDB

(gdb) 
-gdb-exit
^exit

Existing GDB/MI Clients

There are several GDB/MI client implementations in C, C++, Java, Python. I'll list a few that I find easy to read:

  • The inactive libmigdb project (sample program, public interfaces) -- The good news is that it's an attempt at creating a reusable C library. The bad news is that it's not well maintained, e.g. I think it's missing GDB non-stop mode and catchpoint commands support, features that your use case would likely need.
  • python-gdb-mi -- Quite readable if you know Python
  • The C++ GDB/MI client code in QtCreator -- Also quite readable though it's written as part of an abstraction layer to support multiple debugger engines.

You might want to also browse this list of GDB frontends.

这篇关于为GDB编写前端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆