From: Mike Krogh <krogh@ceintl.com>
To: gdb@sourceware.cygnus.com
Cc: krogh@ceintl.com
Subject: debugging a dynamically loaded library
Date: Wed, 29 Aug 2001 13:45:00 -0000 [thread overview]
Message-ID: <15245.21579.555348.285018@gomer.ceintl.com> (raw)
Can someone explain how to debug subroutines that are loaded via
dlopen()/dlsym()? Specifically I'd like to compile and link dso.c
into dso.so and then compile main.c and have it dynamically load
dso.so. Once that is done, I'd like to get gdb to stop in
dso_init(int i) from ./dso.so.
I'm compiling with the following:
cc -g -c dso.c
cc -shared -g -o dso.so dso.o
cc -rdynamic -o main main.c -ldl
Executing ./main works fine. I just can't get gdb to stop anywhere
within dso.c. I've tried using 'add-symbol-file dso.so <address>'
without success.
I'm running under RedHat 7.1 and RedHat 6.2. I've also tried the
8/29/01 gdb dev snapshot.
Thanks,
Mike
/********************** main.c **********************/
#include <stdio.h>
#include <dlfcn.h>
#include "dso.h"
int
main(int argc, char *argv[]) {
void *handle;
void (*init)(int);
void (*incr)(int);
char *error;
int i;
if (!(handle = dlopen("./dso.so", RTLD_NOW|RTLD_GLOBAL))) {
fputs(dlerror(), stderr);
exit(1);
}
init = dlsym(handle, "dso_init");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "%s\n", error);
exit(1);
} else
fprintf(stderr, "Do `add-symbol-file dso.so 0x%x`", init);
incr = dlsym(handle, "dso_increment");
if ((error = dlerror()) != NULL) {
fprintf(stderr, "%s\n", error);
exit(1);
}
(*init)(5);
for (i=0; i<10; i++)
(*incr)(2);
dlclose(handle);
return 0;
}
/********************** dso.c **********************/
#include <stdio.h>
static int value;
void
dso_init(int i) {
value = i;
fprintf(stderr, "dso_init: initialized with %d\n", i);
}
void
dso_increment(int i) {
value += i;
fprintf(stderr, "dso_increment: i = %d value = %d\n", i, value);
}
/********************** dso.c **********************/
#ifndef DSO_H
#define DSO_H
void dso_init(int i);
void dso_increment(int i);
#endif /* DSO_H */
--
-
+-----------------------------------------------------------------+
| Mike Krogh .~. 919-363-0883 |
| Computational Engineering Intl. /V\ fax 919-363-0833 |
| 2166 N. Salem St., Suite 101 // \\ krogh@ceintl.com |
| Apex, NC 27502 /( )\ www.ceintl.com |
| EnSight/EnLiten/EnVideo ^`~'^ |
+-----------------------------------------------------------------+
next reply other threads:[~2001-08-29 13:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-08-29 13:45 Mike Krogh [this message]
2001-08-29 15:41 ` Kevin Buettner
2001-08-29 16:07 ` H . J . Lu
2001-08-29 16:59 ` Kevin Buettner
2001-09-03 15:58 ` Kevin Buettner
2001-09-05 22:29 ` H . J . Lu
2001-09-05 23:05 ` Kevin Buettner
2001-09-06 10:25 ` H . J . Lu
2001-09-18 14:11 ` Mike Krogh
2001-09-18 14:54 ` Kevin Buettner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=15245.21579.555348.285018@gomer.ceintl.com \
--to=krogh@ceintl.com \
--cc=gdb@sourceware.cygnus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox