本文介绍了gdb将评估的原始结果传递给自定义的python函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

amd64,寄存器 $ rdi 是指向/ home / il / gammu-git / src / gammu / libgammu / tls / x86_64的指针/libpthread.so.0



这里看一个例子:

  define foo 
py print gdb.execute(output $ arg0,to_string = True).strip(''')
end




$ b $ p $($) foo(char *)$ rdi
/home/il/gammu-git/src/gammu/libgammu/tls/x86_64/libpthread.so.0

但是,输出命令也会输出字符串的地址:

 (gdb)foo(char *)$ rdi 
0x7fffffffe180/ home / il / gammu-git / src / gammu / libgammu / tls / x86_64 / libpthread .so.0


解决方案

gdb语法是一团糟,而不是MS-DOS的命令行。



使用6个简单步骤,您可以将任意字符串传递给python:

  define foo 
#重置便利性变量,或者得到'To o许多数组元素'
set $ foo_arg0 = 0
#$ arg0扩展得太早,无法直接在python中使用
set $ foo_arg0 = $ arg0

#parse_and_eval()受打印设置的影响,wtf?

#不显示字符串的地址
set print addr off
#print long string
设置打印元素0
#删除'<重复n次>'
set print repeats unlimited

#parse_and_eval()返回带引号的字符串。用eval取消引用
py s = eval(str(gdb.parse_and_eval($ foo_arg0)))
py print s
end

(gdb)foo abc
abc
(gdb)foo $ val
def
(gdb)foo(char *)$ rdi
/ home / il / gammu-git / src /gammu/libgammu/tls/x86_64/libpthread.so.0


amd64, register $rdi is a pointer to "/home/il/gammu-git/src/gammu/libgammu/tls/x86_64/libpthread.so.0"

Seen here an example:

define foo
py print gdb.execute("output $arg0", to_string=True).strip('"')
end

expected:

(gdb) foo (char*)$rdi
/home/il/gammu-git/src/gammu/libgammu/tls/x86_64/libpthread.so.0

However, the output command also prints the address of the string:

(gdb) foo (char*)$rdi
0x7fffffffe180 "/home/il/gammu-git/src/gammu/libgammu/tls/x86_64/libpthread.so.0
解决方案

gdb syntax is a mess, worse than the command line of MS-DOS.

With 6 "simple" steps you can pass arbitrary string to python:

define foo
    # reset convenience var., or get 'Too many array elements'
    set $foo_arg0 = 0
    # $arg0 expanded too early, can't use it directly in python
    set $foo_arg0 = $arg0
    #
    # parse_and_eval() affected by print settings, wtf?
    #
    # don't print address of a string
    set print addr off
    # print long string
    set print elements 0
    # get rid of '<repeats n times>'
    set print repeats unlimited
    #
    # parse_and_eval() returns quoted string. Unquote with eval
    py s = eval(str(gdb.parse_and_eval("$foo_arg0")))
    py print s
end

(gdb) foo "abc"
abc
(gdb) foo $val
def
(gdb) foo (char*)$rdi
/home/il/gammu-git/src/gammu/libgammu/tls/x86_64/libpthread.so.0

这篇关于gdb将评估的原始结果传递给自定义的python函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 13:14