gdb-python

How to start GDB for C++ called from Python?

[亡魂溺海] 提交于 2020-06-29 04:00:14
问题 I need to debug a C++ function that is called from Python code. How to start GDB (or better DDD) in such a way that it debugs the C++ code called from a given Python command line? The given Python command line is: python3 -m e2e.Tests.Libs.HundredEightyOneTest It calls a C++ code that I need to debug. 回答1: My recommendation: recompile your python interpreter from its source code (so it gets compiled with DWARF debug information, practically speaking with GCC invoked as gcc -Wall -O -g ). Once

gdb python : How to iterate through a kernel linked list inside a structure

早过忘川 提交于 2019-12-24 20:48:46
问题 using gdb-python script, i am trying to print data structure which includes kernel data structures and lists(e.g. struct list_head), the structure is struct my_struct { struct my_hardware_context ahw; struct net_device *netdev; struct pci_dev *pdev; struct list_head mac_list; struct list_head wait_list; .... .... }; So while iterating this struct my_struct, how to identify there is a linked list inside this structure as There is no any TYPE_CODE_ constant for Linked list in gdb manual and if

How to convert a gdb Value to a python numeral object while debugging C program

試著忘記壹切 提交于 2019-12-22 00:08:53
问题 I'm using python2.6's gdb module while debugging a C program, and would like to convert a gdb.Value instance into a python numeral object (variable) based off the instance's '.Type'. E.g. turn my C program's SomeStruct->some_float_val = 1./6; to a Python gdb.Value via sfv=gdb.parse_and_eval('SomeStruct->some_double_val') , but THEN turn this into a double precision floating point python variable -- knowing that str(sfv.type.strip_typedefs())=='double' and its size is 8B -- WITHOUT just

gdb-python: why below code is not working under gdb?

隐身守侯 提交于 2019-12-12 00:27:29
问题 below code is working fine as a python code(without gdb module), but it is not working inside gdb? #!/usr/bin/env python import csv import gdb list = [] x = open("file.txt") with x as csv_data: entries = csv.reader(csv_data, delimiter=",") for entry in entries: list.append({ "name": entry[0], "type": entry[1], "link": entry[2], "level": entry[3] }) the error is : (gdb) source script.py File "script.py", line 6 with x as csv_data: ^ SyntaxError: invalid syntax file.txt is: Mac, char, list, one

Can GDB set a breakpoint on a sequence of function calls?

浪子不回头ぞ 提交于 2019-12-11 00:03:36
问题 I'd like to inspect some global variables before a crash happens. The issue only reproduces on a certain stack trace and setting a breakpoint on the innermost function (or any other from the stack) will not get me close enough. Can I achieve the result of breaking only when the top of the stack contains something like this ? #0 __GI_connect #1 curl_connect #2 get_file #3 init_assets Just doing b init_assets c b get_file c ... doesn't work since init_assets is called multiple times and it

How to pass arguments to a python gdb script launched from command line

◇◆丶佛笑我妖孽 提交于 2019-12-06 09:29:00
问题 I'd like to pass some command line arguments to a python script run via gdb command, but importing the gdb module in python removes the argv attribute from sys. How do I access arg1 and arg2 within my python script shown in my example? Command line execution: $ gdb -x a.py --args python -arg1 -arg2 a.py: #!/usr/bin/env python import gdb import sys print('The args are: {0}'.format(sys.argv)) gdb.execute('quit') Error raised: AttributeError: 'module' object has no attribute 'argv' Versions: GNU

How to convert a gdb Value to a python numeral object while debugging C program

半腔热情 提交于 2019-12-04 17:26:04
I'm using python2.6's gdb module while debugging a C program, and would like to convert a gdb.Value instance into a python numeral object (variable) based off the instance's '.Type'. E.g. turn my C program's SomeStruct->some_float_val = 1./6; to a Python gdb.Value via sfv=gdb.parse_and_eval('SomeStruct->some_double_val') , but THEN turn this into a double precision floating point python variable -- knowing that str(sfv.type.strip_typedefs())=='double' and its size is 8B -- WITHOUT just converting through a string using dbl=float(str(sfv)) or Value.string() but rather something like unpacking

gdb python: Walking through array of structures

心不动则不痛 提交于 2019-12-02 16:59:28
问题 Can't we traverse the array of structs ? I mean for each index by checking the content of structs and print each field accordingly? As we can do for a struct like s = gdb.parse_and_eval(expr) for k in s.type.keys(): v = s[k] if is_pointer(v): ..... elif is_array(v): ..... How to get access control on elements at each indices of an array? 回答1: You can index an array using the [] notation. Like, if 'v' is a gdb.Value representing an array or a pointer, you can fetch the 5th element with v[5].

gdb python: Walking through array of structures

心不动则不痛 提交于 2019-12-02 07:50:36
Can't we traverse the array of structs ? I mean for each index by checking the content of structs and print each field accordingly? As we can do for a struct like s = gdb.parse_and_eval(expr) for k in s.type.keys(): v = s[k] if is_pointer(v): ..... elif is_array(v): ..... How to get access control on elements at each indices of an array? You can index an array using the [] notation. Like, if 'v' is a gdb.Value representing an array or a pointer, you can fetch the 5th element with v[5]. The manual has a long section on the Value API that explains all of this. 来源: https://stackoverflow.com

gdb python : Can anyone explain me how to use this script written in this post?

落花浮王杯 提交于 2019-12-01 11:23:19
问题 How to do it for a c code..? Is it possible..? I read this post. I also want to do similar things but i am not able to use the given updated script at link GDB-Python scripting: any samples iterating through C/C++ struct fields I followed the following steps to test : my source code name was : test.c and pretty.py gcc -g test.c gdb test (gdb) source pretty.py (gdb) run (gdb) print <stcruct object> How to use this script? 回答1: That script implements a new GDB command, wzd which takes a C