Skip to content
Snippets Groups Projects
Commit be228006 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "lrdp-v2: add container_of and sibling_field_addr convenience functions"

parents 5400f10b e0e640fd
No related branches found
No related tags found
No related merge requests found
# 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))
......
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment