diff --git a/linux-ramdump-parser-v2/gdbmi.py b/linux-ramdump-parser-v2/gdbmi.py index cdccdd078ea4d0622ca0d35d659522dc7158874a..e7cec1085def82405cc1794514cb00c318b8f5f2 100644 --- a/linux-ramdump-parser-v2/gdbmi.py +++ b/linux-ramdump-parser-v2/gdbmi.py @@ -1,4 +1,4 @@ -# Copyright (c) 2013, The Linux Foundation. All rights reserved. +# Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 and @@ -158,6 +158,31 @@ class GdbMI(object): result = self._run_for_one(cmd) return gdb_hex_to_dec(result) + def container_of(self, ptr, the_type, member): + return ptr - self.field_offset(the_type, member) + + def sibling_field_addr(self, ptr, parent_type, member, sibling): + """Returns the address of a sibling field within the parent + structure. + + Example: + + Given: + struct pizza { + int price; + int *qty; + }; + + int quanitity = 42; + struct pizza mypizza = {.price = 10, .qty = &quanitity}; + + qtyp = dump.addr_lookup('quantity') + price = dump.read_int(gdbmi.sibling_field_addr(qtyp, 'struct pizza', 'qty', 'price')) + + """ + return self.container_of(ptr, parent_type, member) + \ + self.field_offset(parent_type, sibling) + def sizeof(self, the_type): """Returns the size of the type specified by `the_type'.""" result = self._run_for_one('print /x sizeof({0})'.format(the_type)) diff --git a/linux-ramdump-parser-v2/ramdump.py b/linux-ramdump-parser-v2/ramdump.py index 71d89b9c95f932511086fa0ac3a7a26d020c9895..3e2a0f5a8f02c9d2019c3a5bac3b4f21901b0f4e 100644 --- a/linux-ramdump-parser-v2/ramdump.py +++ b/linux-ramdump-parser-v2/ramdump.py @@ -869,6 +869,18 @@ class RamDump(): except gdbmi.GdbMIException: pass + def container_of(self, ptr, the_type, member): + try: + return self.gdbmi.container_of(ptr, the_type, member) + except gdbmi.GdbMIException: + pass + + def sibling_field_addr(self, ptr, parent_type, member, sibling): + try: + return self.gdbmi.sibling_field_addr(ptr, parent_type, member, sibling) + except gdbmi.GdbMIException: + pass + def unwind_lookup(self, addr, symbol_size=0): if (addr is None): return ('(Invalid address)', 0x0)