From da2b275658af2cb973a3c8b6e3c17ed47c03e560 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Sun, 19 May 2019 11:25:06 -0400 Subject: [PATCH] Update developer customizations * .ccls: Remove -std=c99: it disables __attribute__ causing warnings. * .dir-locals.el: Force the C coding style to "gnu". * make-gdb.py: Add GDB macros for pretty-printing GNU make structs. * scripts/copyright-update: Use GNULIB_SRCDIR to find update-copyright. --- .ccls | 1 - .dir-locals.el | 1 + .gitignore | 1 + make-gdb.py | 175 +++++++++++++++++++++++++++++++++++++++ scripts/copyright-update | 9 +- 5 files changed, 182 insertions(+), 5 deletions(-) create mode 100644 make-gdb.py diff --git a/.ccls b/.ccls index 0f31f5ea..d6d6cd79 100644 --- a/.ccls +++ b/.ccls @@ -1,5 +1,4 @@ clang -%c -std=c99 %h --include=makeint.h -DHAVE_CONFIG_H -Isrc diff --git a/.dir-locals.el b/.dir-locals.el index f71d12d4..30736ec2 100644 --- a/.dir-locals.el +++ b/.dir-locals.el @@ -14,4 +14,5 @@ "/tests/work$" "/make-[0-9]")) )) + (c-mode . ((c-file-style . "gnu"))) ) diff --git a/.gitignore b/.gitignore index 429e2790..2f5023e7 100644 --- a/.gitignore +++ b/.gitignore @@ -36,6 +36,7 @@ stamp-h1 gmk-default.h loadavg make +*.i *.o *.a *.exe diff --git a/make-gdb.py b/make-gdb.py new file mode 100644 index 00000000..d5a52854 --- /dev/null +++ b/make-gdb.py @@ -0,0 +1,175 @@ +import re + +import gdb #pylint: disable=import-error +import gdb.printing #pylint: disable=import-error + +# Memoize types we commonly use +_TYPES = {} +def getType(tname): + global _TYPES + if tname not in _TYPES: + tn = tname.rstrip('*') + if tn not in _TYPES: + _TYPES[tn] = gdb.lookup_type(tn) + while tn != tname: + # Want a pointer type + t = tn + tn += '*' + _TYPES[tn] = _TYPES[t].pointer() + return _TYPES[tname] + +class ShowArgv(gdb.Function): + """Return the pretty-print of a null-terminated array of strings + + Argument: + A char** where the last one is NULL (e.g., argv) + """ + + def __init__(self): + gdb.Function.__init__(self, "showargv") + + def invoke(self, argv): + str = '[' + i = 0 + while argv[i] != 0: + if i > 0: + str += ', ' + str += argv[i].string() + i += 1 + str += ']' + return str + +ShowArgv() + + +class FileLocation(object): + """Print a file location""" + + def __init__(self, val): + self.val = val + + def to_string(self): + if long(self.val['filenm']): + return "%s:%d" % (str(self.val['filenm']), self.val['lineno']) + return '' + +class VariablePrinter(object): + """Print a struct variable""" + + def __init__(self, val): + self.val = val + + def to_string(self): + if self.val['append']: + a = '+=' + elif self.val['conditional']: + a = '?=' + else: + a = '=' + flags = [] + s = str(self.val['flavor']) + if s != 'f_bogus': + flags.append(s) + s = str(self.val['origin']) + if s != 'o_default': + flags.append(s) + s = str(self.val['export']) + if s != 'v_default': + flags.append(s) + return '%s[%s]: "%s" %s "%s"' % ( + self.val['fileinfo'], ','.join(flags), + self.val['name'].string(), a, self.val['value'].string()) + +class HashTablePrinter(object): + """Manage a hash table.""" + + DELITEM = None + + def __init__(self, val): + self.val = val + + def to_string(self): + return "size=%d, capacity=%d, empty=%d, collisions=%d, rehashes=%d" % ( + self.val['ht_size'], self.val['ht_capacity'], + self.val['ht_empty_slots'], self.val['ht_collisions'], + self.val['ht_rehashes']) + + def children(self): + for (i, v) in self.iterator(): + nm = '[%d] ' % i + yield (nm, i) + yield (nm, v) + + def iterator(self): + if HashTablePrinter.DELITEM is None: + HashTablePrinter.DELITEM = gdb.lookup_global_symbol('hash_deleted_item').value() + lst = self.val['ht_vec'] + for i in xrange(0, self.val['ht_size']): + v = lst[i] + if long(v) != 0 and v != HashTablePrinter.DELITEM: + yield (i, v) + + def display_hint(self): + return 'map' + +class VariableSetPrinter(object): + """Print a variable_set""" + + def __init__(self, val): + self.tbl = HashTablePrinter(val['table']) + + def to_string(self): + return self.tbl.to_string() + + def children(self): + for (i, v) in self.tbl.iterator(): + ptr = v.cast(getType('struct variable*')) + nm = '[%d] ' % (i) + yield (nm, ptr) + yield (nm, str(ptr.dereference())) + + def display_hint(self): + return 'map' + +class VariableSetListPrinter(object): + """Print a variable_set_list""" + + GLOBALSET = None + + def __init__(self, val): + self.val = val + + def to_string(self): + return str(self.val.address) + + def children(self): + if VariableSetListPrinter.GLOBALSET is None: + block = gdb.lookup_global_symbol('init_hash_global_variable_set').symtab.static_block() + VariableSetListPrinter.GLOBALSET = gdb.lookup_symbol('global_variable_set', block)[0].value().address + ptr = self.val.address + i = 0 + while long(ptr) != 0: + nm = '[%d] ' % (i) + yield (nm, ptr['set']) + if long(ptr['set']) == long(VariableSetListPrinter.GLOBALSET): + yield (nm, "global_variable_set") + else: + yield (nm, str(ptr['set'].dereference())) + i += 1 + ptr = ptr['next'] + + def display_hint(self): + return 'map' + +def build_pretty_printer(): + pp = gdb.printing.RegexpCollectionPrettyPrinter("gnumake") + pp.add_printer('floc', r'^floc$', FileLocation) + pp.add_printer('variable', r'^variable$', VariablePrinter) + pp.add_printer('hashtable', r'^hash_table$', HashTablePrinter) + pp.add_printer('variableset', r'^variable_set$', VariableSetPrinter) + pp.add_printer('variablesetlist', r'^variable_set_list$', VariableSetListPrinter) + return pp + +# Use replace=True so we can re-source this file +gdb.printing.register_pretty_printer(gdb.current_objfile(), + build_pretty_printer(), replace=True) diff --git a/scripts/copyright-update b/scripts/copyright-update index a31cf0a9..2e7c598b 100755 --- a/scripts/copyright-update +++ b/scripts/copyright-update @@ -5,11 +5,14 @@ # # Update GNU make copyrights using gnulib update-copyright -update=${UPDATE_COPYRIGHT:-../../gnulib/build-aux/update-copyright} +update=${UPDATE_COPYRIGHT:-${GNULIB_SRCDIR:-../../gnulib}/build-aux/update-copyright} die () { echo "$*"; exit 1; } run () { + cmd=$(command -v "$update") || die "Cannot locate update-copyright ($update)" + [ -x "$cmd" ] || die "Cannot locate update-copyright ($update)" + EXCLUDE='^\(.*/\.[a-z].*\|.*COPYING\|glob/.*\|src/hash\.[ch]\|ChangeLog\.[0-9]*\|.*/ChangeLog\.[0-9]*\|INSTALL\|doc/make\.texi\)$' force=false @@ -29,12 +32,10 @@ run () { die "Run in a clean workspace (git clean -fdX)" fi - [ -x "$update" ] || die "Cannot locate update-copyright ($update)" - # We use intervals export UPDATE_COPYRIGHT_USE_INTERVALS=1 - "$update" $(find * -type f | grep -v "$EXCLUDE") + "$cmd" $(find * -type f | grep -v "$EXCLUDE") echo "*** Update doc/make.texi copyright by hand!" echo "*** Update src/main.c:print_version() copyright by hand!"