aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2012-04-12 23:09:21 +0200
committerPetr Machata <pmachata@redhat.com>2012-04-12 23:09:21 +0200
commit1429874dee5758cc99c0dae73bd3f928109e53d7 (patch)
tree9931c161d2f7936616c2b90e4b1cdd803bae57d4
parent31b2f9f7296e52aff489138c78be2f8cf9140bbc (diff)
downloadltrace-1429874dee5758cc99c0dae73bd3f928109e53d7.tar.gz
Fix previous commit, which broke the common case
- in this commit I drop a bit of MIPS support. First, I don't think MIPS is supported right now. The multi-threading merge was an invasive change and most arches other than x86 are in fact currently broken. Second, deciding that we shouldn't push a slot just based on address equality is too strong. This would also reject actual recursion, which is a common case (for -x anyway, for -e less so).
-rw-r--r--handle_event.c35
-rw-r--r--testsuite/ltrace.main/branch_func.c8
-rw-r--r--testsuite/ltrace.main/branch_func.exp8
3 files changed, 32 insertions, 19 deletions
diff --git a/handle_event.c b/handle_event.c
index dcc1f8c..8c3c7ce 100644
--- a/handle_event.c
+++ b/handle_event.c
@@ -565,6 +565,15 @@ void *get_count_register (Process *proc);
#endif
static void
+output_right_tos(struct Process *proc)
+{
+ size_t d = proc->callstack_depth;
+ struct callstack_element *elem = &proc->callstack[d - 1];
+ if (proc->state != STATE_IGNORED)
+ output_right(LT_TOF_FUNCTIONR, proc, elem->c_un.libfunc->name);
+}
+
+static void
handle_breakpoint(Event *event)
{
int i, j;
@@ -672,29 +681,26 @@ handle_breakpoint(Event *event)
}
event->proc->return_addr = brk_addr;
+ output_right_tos(event->proc);
+ callstack_pop(event->proc);
+
/* Pop also any other entries that seem like
* they are linked to the current one: they
* have the same return address, but were made
* for different symbols. This should only
* happen for entry point tracing, i.e. for -x
* everywhere, or -x and -e on PPC64. */
- int first = 1;
while (event->proc->callstack_depth > 0) {
struct callstack_element *prev;
size_t d = event->proc->callstack_depth;
prev = &event->proc->callstack[d - 1];
- if (event->proc->state != STATE_IGNORED)
- output_right(LT_TOF_FUNCTIONR,
- event->proc,
- prev->c_un.libfunc->name);
-
- if (prev->c_un.libfunc != libsym
- && prev->return_addr == brk_addr)
- callstack_pop(event->proc);
- else if (!first)
+ if (prev->c_un.libfunc == libsym
+ || prev->return_addr != brk_addr)
break;
- first = 0;
+
+ output_right_tos(event->proc);
+ callstack_pop(event->proc);
}
sbp = address2bpstruct(leader, brk_addr);
@@ -765,7 +771,7 @@ callstack_push_syscall(Process *proc, int sysnum) {
static void
callstack_push_symfunc(Process *proc, struct library_symbol *sym) {
- struct callstack_element *elem, *prev;
+ struct callstack_element *elem;
debug(DEBUG_FUNCTION, "callstack_push_symfunc(pid=%d, symbol=%s)", proc->pid, sym->name);
/* FIXME: not good -- should use dynamic allocation. 19990703 mortene. */
@@ -775,8 +781,7 @@ callstack_push_symfunc(Process *proc, struct library_symbol *sym) {
return;
}
- prev = &proc->callstack[proc->callstack_depth-1];
- elem = &proc->callstack[proc->callstack_depth];
+ elem = &proc->callstack[proc->callstack_depth++];
elem->is_syscall = 0;
elem->c_un.libfunc = sym;
@@ -786,8 +791,6 @@ callstack_push_symfunc(Process *proc, struct library_symbol *sym) {
}
/* handle functions like atexit() on mips which have no return */
- if (elem->return_addr != prev->return_addr)
- proc->callstack_depth++;
if (opt_T || options.summary) {
struct timezone tz;
gettimeofday(&elem->time_spent, &tz);
diff --git a/testsuite/ltrace.main/branch_func.c b/testsuite/ltrace.main/branch_func.c
index 7eff15d..0ce311d 100644
--- a/testsuite/ltrace.main/branch_func.c
+++ b/testsuite/ltrace.main/branch_func.c
@@ -23,9 +23,15 @@
* overflows. */
__attribute__((noinline, optimize(3))) int
+func3(int i)
+{
+ return i + 1;
+}
+
+__attribute__((noinline, optimize(3))) int
func2(int i)
{
- return i * 3;
+ return func3(i * 3);
}
__attribute__((noinline, optimize(3))) int
diff --git a/testsuite/ltrace.main/branch_func.exp b/testsuite/ltrace.main/branch_func.exp
index fb51565..fec5700 100644
--- a/testsuite/ltrace.main/branch_func.exp
+++ b/testsuite/ltrace.main/branch_func.exp
@@ -30,7 +30,7 @@ if { [ltrace_compile $srcdir/$subdir/$srcfile $objdir/$subdir/$binfile executabl
}
# set options for ltrace.
-ltrace_options "-x" "func1" "-x" "func2"
+ltrace_options "-x" "func1" "-x" "func2" "-x" "func3"
# Run PUT for ltarce.
set exec_output [ltrace_runtest $objdir/$subdir $objdir/$subdir/$binfile]
@@ -47,7 +47,11 @@ if [regexp {ELF from incompatible architecture} $exec_output] {
set pattern "func1(.*unfinished"
ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 100
-set pattern "func2(.*)"
+set pattern "func2(.*unfinished"
+ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 100
+set pattern "func3(.*)"
+ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 100
+set pattern "func2.resumed"
ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 100
set pattern "func1.resumed"
ltrace_verify_output ${objdir}/${subdir}/${testfile}.ltrace $pattern 100