a few problems building gdb
by Tom Tromey
I pulled and rebuilt the plugin today on F15 x86-64.
Then I used it to build the gdb 7.4 branch with CC=gcc-with-cpychecker.
I didn't modify the plugin at all.
I can file bugs for these if you'd prefer, just let me know.
I got the appended Python exception trace.
For this:
../../src/gdb/arm-tdep.c:6798:22: error: Unhandled Python exception raised calling 'execute' method
The line in question is:
regmask &= ~(1 << regno);
Also:
../../src/gdb/arm-tdep.c:6464:6: error: comparison against uninitialized data: gcc.VarDecl(32844) at ../../src/gdb/arm-tdep.c:6464
The VarDecl bit seems like a formatting bug.
I wouldn't mind a mode where cpychecker doesn't emit any diagnostics for
functions unrelated to the use of Python. E.g., arm-tdep.c does not
call into Python at all, analyzing most of it seems like a waste of
time.
Finally, while compiling arm-tdep.c, cc1 started using lots and lots of
memory, enough that my machine noticeably slowed down. I C-c'd the
build, and this killed make and gcc -- but not cc1. In the end I had to
resort to kill. So, I surmise that there is some issue with C-c
handling in the plugin.
Tom
/home/tromey/Space/Trunk/gcc-python-plugin/gcc-with-cpychecker -g3 -gdwarf-4 -I. -I../../src/gdb -I../../src/gdb/common -I../../src/gdb/config -DLOCALEDIR="\"/home/tromey/Space/gdb/7.4/install/share/locale\"" -DHAVE_CONFIG_H -I../../src/gdb/../include/opcode -I../../src/gdb/../opcodes/.. -I../../src/gdb/../readline/.. -I../bfd -I../../src/gdb/../bfd -I../../src/gdb/../include -I../libdecnumber -I../../src/gdb/../libdecnumber -I../../src/gdb/gnulib -Ignulib -DTUI=1 -g3 -gdwarf-4 -I/usr/include/python2.7 -I/usr/include/python2.7 -Wall -Wdeclaration-after-statement -Wpointer-arith -Wformat-nonliteral -Wno-pointer-sign -Wno-unused -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts -c -o arm-tdep.o -MT arm-tdep.o -MMD -MP -MF .deps/arm-tdep.Tpo ../../src/gdb/arm-tdep.c
../../src/gdb/arm-tdep.c: In function ‘arm_gdbarch_init’:
../../src/gdb/arm-tdep.c:9672:1: note: this function is too complicated for the reference-count checker to analyze
../../src/gdb/arm-tdep.c: In function ‘arm_record_special_symbol’:
../../src/gdb/arm-tdep.c:9408:1: note: this function is too complicated for the reference-count checker to analyze
../../src/gdb/arm-tdep.c: In function ‘arm_decode_svc_copro’:
../../src/gdb/arm-tdep.c:7694:1: note: this function is too complicated for the reference-count checker to analyze
../../src/gdb/arm-tdep.c: In function ‘arm_decode_ld_st_word_ubyte’:
../../src/gdb/arm-tdep.c:7500:1: note: this function is too complicated for the reference-count checker to analyze
../../src/gdb/arm-tdep.c: In function ‘arm_decode_dp_misc’:
../../src/gdb/arm-tdep.c:7454:1: note: this function is too complicated for the reference-count checker to analyze
../../src/gdb/arm-tdep.c: In function ‘cleanup_block_load_all’:
../../src/gdb/arm-tdep.c:6798:22: error: Unhandled Python exception raised calling 'execute' method
Traceback (most recent call last):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/__init__.py", line 52, in execute
self.show_possible_null_derefs)
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/refcounts.py", line 2706, in check_refcounts
limits=limits)
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2633, in iter_traces
for trace in iter_traces(fun, facets, newprefix, limits):
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2601, in iter_traces
transitions = curstate.get_transitions()
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 1766, in get_transitions
return self._get_transitions_for_stmt(stmt)
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 1793, in _get_transitions_for_stmt
return self._get_transitions_for_GimpleAssign(stmt)
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2243, in _get_transitions_for_GimpleAssign
value = self.eval_rhs(stmt)
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 2186, in eval_rhs
c = a.eval_binop(stmt.exprcode, b, stmt.lhs.type, stmt.loc)
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 402, in eval_binop
newvalue = eval_binop(exprcode, self.value, rhs.value)
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 314, in eval_binop
result = inner()
File "/home/tromey/Space/Trunk/gcc-python-plugin/libcpychecker/absinterp.py", line 303, in inner
return a << b
ValueError: negative shift count
../../src/gdb/arm-tdep.c: In function ‘arm_copy_ldr_str_ldrb_strb’:
../../src/gdb/arm-tdep.c:6667:1: note: this function is too complicated for the reference-count checker to analyze
../../src/gdb/arm-tdep.c: In function ‘arm_copy_extra_ld_st’:
../../src/gdb/arm-tdep.c:6464:6: error: comparison against uninitialized data: gcc.VarDecl(32844) at ../../src/gdb/arm-tdep.c:6464
../../src/gdb/arm-tdep.c:6443:6: note: when taking False path at: if (!insn_references_pc (insn, 0x000ff00ful))
../../src/gdb/arm-tdep.c:6446:7: note: reaching: if (debug_displaced)
../../src/gdb/arm-tdep.c:6446:6: note: when taking True path at: if (debug_displaced)
../../src/gdb/arm-tdep.c:6447:24: note: reaching: fprintf_unfiltered (gdb_stdlog, "displaced: copying %sextra load/store "
../../src/gdb/arm-tdep.c:6447:24: note: when taking True path at: fprintf_unfiltered (gdb_stdlog, "displaced: copying %sextra load/store "
../../src/gdb/arm-tdep.c:6447:24: note: reaching: fprintf_unfiltered (gdb_stdlog, "displaced: copying %sextra load/store "
../../src/gdb/arm-tdep.c:6453:6: note: taking False path at: if (opcode < 0)
../../src/gdb/arm-tdep.c:6457:36: note: reaching: dsc->tmp[0] = displaced_read_reg (regs, dsc, 0);
../../src/gdb/arm-tdep.c:6457:15: note: when treating unknown struct displaced_step_closure * from ../../src/gdb/arm-tdep.c:6430 as non-NULL at: dsc->tmp[0] = displaced_read_reg (regs, dsc, 0);
../../src/gdb/arm-tdep.c:6460:6: note: taking False path at: if (!immed)
../../src/gdb/arm-tdep.c:6463:31: note: reaching: rt_val = displaced_read_reg (regs, dsc, rt);
../../src/gdb/arm-tdep.c:6464:6: note: found 2 similar trace(s) to this
../../src/gdb/arm-tdep.c:6431:1: note: graphical error report for function 'arm_copy_extra_ld_st' written out to 'arm-tdep.c.arm_copy_extra_ld_st-refcount-errors.html'
12 years, 3 months
change how decl_as_string is handled
by Tom Tromey
Jakub pointed out this cute typeof trick on the gcc thread about
decl_as_string. This patch changes the plugin to use it.
The end result is similar to using dlsym, but has the benefit of being
type-safe.
If you'd prefer I can reword the patch to continue to use dlsym, and
just change the declaration of the local decl_as_string to use typeof.
That would also be type-safe.
This uses a GCC extension, but I figured that was ok for a GCC plugin.
This passed all tests on x86-64 F15.
Tom
>From 51353c7cc59c471a764c1f4fa99171810f7432b1 Mon Sep 17 00:00:00 2001
From: Tom Tromey <tromey(a)redhat.com>
Date: Tue, 13 Dec 2011 12:11:42 -0700
Subject: [PATCH] redeclare decl_as_string as weak
This changes gcc-python-tree.c to redeclare decl_as_string
as weak, rather than using dlsym. This has the same effect,
but is type-safe.
---
gcc-python-tree.c | 30 +++++++++++++-----------------
1 files changed, 13 insertions(+), 17 deletions(-)
diff --git a/gcc-python-tree.c b/gcc-python-tree.c
index 3ba3b4c..384be65 100644
--- a/gcc-python-tree.c
+++ b/gcc-python-tree.c
@@ -25,6 +25,19 @@
#include "cp/cp-tree.h" /* for TFF_* for use by gcc_FunctionDecl_get_fullname */
+/*
+ Unfortunately, decl_as_string() is only available from the C++
+ frontend: cc1plus (it's defined in gcc/cp/error.c).
+
+ See http://gcc.gnu.org/ml/gcc/2011-11/msg00504.html
+
+ Hence we redeclare the symbol as weak, and then check its definition
+ against 0 before using it.
+*/
+
+__typeof__ (decl_as_string) decl_as_string __attribute__ ((weak));
+
+
//#include "rtl.h"
/*
"struct rtx_def" is declarted within rtl.h, c.f:
@@ -158,25 +171,8 @@ error:
PyObject *
gcc_FunctionDecl_get_fullname(struct PyGccTree *self, void *closure)
{
- /*
- Unfortunately, decl_as_string() is only available from the C++
- frontend: cc1plus (it's defined in gcc/cp/error.c).
-
- See http://gcc.gnu.org/ml/gcc/2011-11/msg00504.html
-
- Hence we try to dynamically load the symbol, which will be already
- present if we were loaded by cc1plus (for C++), and not be found
- otherwise
-
- Declared in cp/cp-tree.h as:
- extern const char *decl_as_string (tree, int);
- */
-
- const char *(*decl_as_string)(tree, int);
const char *str;
- decl_as_string = dlsym(RTLD_DEFAULT, "decl_as_string");
-
if (NULL == decl_as_string) {
return PyErr_Format(PyExc_RuntimeError,
"attribute 'fullname' is only available when compiling C++ code");
--
1.7.6.4
12 years, 4 months
Newbie questions
by Stephan Bergmann
Hi all,
Playing around with the plugin (in the hope of eventually using it to
find out interesting things in the LibreOffice code base), I'm not sure
I'm trying to use it in a sensible manner. Maybe somebody on this list
can set me on track?
As a first experiment, I wanted to do the following: LO has a string
class rtl::OUString with member functions getLength and isEmpty. Now, I
wanted to find places in the code that call getLength and check the
result against null, instead of calling isEmpty directly.
My first doubt is whether doing that at Gimple-level is practical at all
(and whether the plugin would also support doing it at another, more
appropriate level that is closer to the original AST)?
I figure I need to find GimpleCall statements that call
rtl::OUString::getLength and trace their lhs variables (potentially
through further GimpleAssign statements) to GimpleCond statements.
Something like
class TryOut(gcc.GimplePass):
def execute(self, fun):
for bb in fun.cfg.basic_blocks:
if bb.gimple:
for stmt in bb.gimple:
print ' stmt:', stmt
if isinstance(stmt, gcc.GimpleCall):
name = stmt.fndecl.name
# ...
elif isinstance(stmt, gcc.GimpleAssign):
# ...
elif isinstance(stmt, gcc.GimpleCond):
# ...
But the first obstacle is already how to determine the full name of the
called function, as stmt.fndecl.name would only be "getLength", without
the class and namespace information.
Any pointers appreciated,
Stephan
12 years, 4 months