如何在GDB的mi解释器模式下通过钩子检测GDB退出? [英] How to detect GDB exit via hooks in GDB's mi interpreter mode?

查看:55
本文介绍了如何在GDB的mi解释器模式下通过钩子检测GDB退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在"mi解释器"模式下运行GDB,并且正在使用用户定义的挂钩来检测诸如stop,quit等事件.

I am running GDB in "mi interpreter" mode and I am using user defined hooks to detect events such as stop,quit etc.

无论何时发生该事件,挂钩都会打印一些信息,这些信息将被重定向到另一个日志文件.

Whenever the event occurs the hook will print some information which are redirected to a different log file.

另一个应用程序将从此日志文件中读取内容并进行处理.

Another application will read the contents from this log file and process it.

我写了一个钩子来检测GDB退出,如图所示:

I have written a hook to detect GDB exit, as illustrated:

define hook-quit
set logging file D:\log\task.log
set logging on
print "GDB end detected"
set logging off
end

在GDB的控制台模式下,当GDB退出时,上述挂钩将成功执行.

In GDB's console mode, the above hook executes successfully when GDB exits.

但是,在GDB的"mi解释器模式"下,该挂钩无法执行.

However in GDB's "mi interpreter mode", the hook fails to execute.

在"mi解释器模式"下,是否还有其他钩子(或任何方法)可用于检测GDB退出.

Is there any alternative hook (or any method) for detecting GDB exit in "mi interpreter mode".

Windows 7
工具链:arm-none-eabi(命令: arm-none-eabi-gdb.exe --interpreter = mi D:\ test.elf)

Windows 7
Toolchain: arm-none-eabi (command: arm-none-eabi-gdb.exe --interpreter=mi D:\test.elf)

推荐答案

想到了几种方法.

一种方法是使用Python在打印到日志的退出"钩子处进行写操作. Python出口挂钩应在gdb出口期间运行.

One is to use Python to write at "at exit" hook that prints to the log. The Python exit hooks should be run during gdb exit.

另一种方法是在不同的层上进行写操作:以调用gdb -i=mi的方式进行写操作,或者编写一个包装程序来调用gdb,然后在gdb退出时写入日志.

Another is to do the writing at a different layer: either in whatever is invoking gdb -i=mi, or by writing a wrapper script that invokes gdb and then writes to the log when gdb exits.

这篇关于如何在GDB的mi解释器模式下通过钩子检测GDB退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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