Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* debugging a dynamically loaded library
@ 2001-08-29 13:45 Mike Krogh
  2001-08-29 15:41 ` Kevin Buettner
  0 siblings, 1 reply; 10+ messages in thread
From: Mike Krogh @ 2001-08-29 13:45 UTC (permalink / raw)
  To: gdb; +Cc: krogh

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         ^`~'^                           |
+-----------------------------------------------------------------+


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2001-09-18 14:54 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-08-29 13:45 debugging a dynamically loaded library Mike Krogh
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox