Add argument that defines whether we should enable breakpoints
diff --git a/ChangeLog b/ChangeLog
index e88474c..4e1bd90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -11,6 +11,12 @@
2011-05-09 Petr Machata <pmachata@redhat.com>
+ * common.h (breakpoints_init, insert_breakpoint, open_program):
+ Pass an extra argument that defines whether we should enable
+ breakpoints.
+
+2011-05-09 Petr Machata <pmachata@redhat.com>
+
* execute_program.c (execute_program): Returns pid_t.
* proc.c (open_program): Always assumes that pid is != 0.
* common.h, libltrace.c (ltrace_init): Adapt to above.
diff --git a/breakpoints.c b/breakpoints.c
index 41262a5..f215075 100644
--- a/breakpoints.c
+++ b/breakpoints.c
@@ -22,7 +22,7 @@
void
insert_breakpoint(Process *proc, void *addr,
- struct library_symbol *libsym) {
+ struct library_symbol *libsym, int enable) {
Breakpoint *sbp;
#ifdef __arm__
@@ -55,8 +55,10 @@
proc->thumb_mode = 0;
#endif
sbp->enabled++;
- if (sbp->enabled == 1 && proc->pid)
+ if (sbp->enabled == 1 && enable) {
+ assert(proc->pid != 0);
enable_breakpoint(proc, sbp);
+ }
}
void
@@ -170,7 +172,8 @@
}
void
-breakpoints_init(Process *proc) {
+breakpoints_init(Process *proc, int enable)
+{
struct library_symbol *sym;
debug(DEBUG_FUNCTION, "breakpoints_init(pid=%d)", proc->pid);
@@ -216,10 +219,10 @@
}
}
}
- for (sym = proc->list_of_symbols; sym; sym = sym->next) {
- /* proc->pid==0 delays enabling. */
- insert_breakpoint(proc, sym2addr(proc, sym), sym);
- }
+
+ for (sym = proc->list_of_symbols; sym; sym = sym->next)
+ insert_breakpoint(proc, sym2addr(proc, sym), sym, enable);
+
proc->callstack_depth = 0;
proc->breakpoints_enabled = -1;
}
@@ -234,7 +237,7 @@
while (sym) {
if (sym->needs_init) {
- insert_breakpoint(proc, sym2addr(proc, sym), sym);
+ insert_breakpoint(proc, sym2addr(proc, sym), sym, 1);
if (sym->needs_init && !sym->is_weak) {
fprintf(stderr,
"could not re-initialize breakpoint for \"%s\" in file \"%s\"\n",
diff --git a/common.h b/common.h
index 179ce95..a7234a5 100644
--- a/common.h
+++ b/common.h
@@ -225,14 +225,15 @@
extern pid_t execute_program(const char * command, char ** argv);
extern int display_arg(enum tof type, Process * proc, int arg_num, arg_type_info * info);
extern Breakpoint * address2bpstruct(Process * proc, void * addr);
-extern void breakpoints_init(Process * proc);
-extern void insert_breakpoint(Process * proc, void * addr, struct library_symbol * libsym);
+extern void breakpoints_init(Process * proc, int enable);
+extern void insert_breakpoint(Process * proc, void * addr,
+ struct library_symbol * libsym, int enable);
extern void delete_breakpoint(Process * proc, void * addr);
extern void enable_all_breakpoints(Process * proc);
extern void disable_all_breakpoints(Process * proc);
extern void reinitialize_breakpoints(Process *);
-extern Process * open_program(char * filename, pid_t pid);
+extern Process * open_program(char * filename, pid_t pid, int init_breakpoints);
extern void open_pid(pid_t pid);
extern void show_summary(void);
extern arg_type_info * lookup_prototype(enum arg_type at);
diff --git a/handle_event.c b/handle_event.c
index 3e08179..a9bdea1 100644
--- a/handle_event.c
+++ b/handle_event.c
@@ -418,7 +418,7 @@
proc->filename = pid2name(proc->pid);
saved_pid = proc->pid;
proc->pid = 0;
- breakpoints_init(proc);
+ breakpoints_init(proc, 0);
proc->pid = saved_pid;
proc->callstack_depth = 0;
continue_process(proc->pid);
@@ -689,7 +689,7 @@
elem->return_addr = proc->return_addr;
if (elem->return_addr) {
- insert_breakpoint(proc, elem->return_addr, NULL);
+ insert_breakpoint(proc, elem->return_addr, NULL, 1);
}
/* handle functions like atexit() on mips which have no return */
diff --git a/libltrace.c b/libltrace.c
index 1d7f190..5408fb6 100644
--- a/libltrace.c
+++ b/libltrace.c
@@ -108,7 +108,7 @@
}
}
if (command) {
- open_program(command, execute_program(command, argv));
+ open_program(command, execute_program(command, argv), 0);
}
opt_p_tmp = opt_p;
while (opt_p_tmp) {
diff --git a/proc.c b/proc.c
index dcad707..9e27b11 100644
--- a/proc.c
+++ b/proc.c
@@ -15,7 +15,7 @@
#include "common.h"
Process *
-open_program(char *filename, pid_t pid) {
+open_program(char *filename, pid_t pid, int enable) {
Process *proc;
assert(pid != 0);
proc = calloc(sizeof(Process), 1);
@@ -31,10 +31,10 @@
proc->unwind_as = unw_create_addr_space(&_UPT_accessors, 0);
#endif /* defined(HAVE_LIBUNWIND) */
- breakpoints_init(proc);
proc->next = list_of_processes;
list_of_processes = proc;
+ breakpoints_init(proc, enable);
return proc;
}
@@ -58,7 +58,7 @@
return;
}
- proc = open_program(filename, pid);
+ proc = open_program(filename, pid, 1);
continue_process(pid);
proc->breakpoints_enabled = 1;
}
diff --git a/sysdeps/linux-gnu/proc.c b/sysdeps/linux-gnu/proc.c
index fbc3d99..eca3548 100644
--- a/sysdeps/linux-gnu/proc.c
+++ b/sysdeps/linux-gnu/proc.c
@@ -190,7 +190,7 @@
insert_breakpoint(lm_add->proc,
sym2addr(lm_add->proc,
library_symbols),
- library_symbols);
+ library_symbols, 1);
}
}
do_close_elf(<e);
@@ -279,7 +279,7 @@
add_library_symbol(rdbg->r_brk, "", &library_symbols, LS_TOPLT_NONE, 0);
insert_breakpoint(proc, sym2addr(proc, library_symbols),
- library_symbols);
+ library_symbols, 1);
crawl_linkmap(proc, rdbg, hook_libdl_cb, &data);