Debugging Dynamic library

Hi,

I’m not sure this is the best area to post this but it’s the one that fits best I guess. Here is my problem.

I have an application that upon starting up loads a dynamic library (for which I have the source). Then calls a function in the library everytime a timer expires (I use signals to be interrupted when the timer expires).

I want to add a breakpoint in a subsequent library call, for example

timer_fct → libcall1 → libcall2 → (break here) libcall3

The problem is that when I had the breakpoint, it never gets hit. But if i put a break point at libcall2 it will get hit and then step through it will pass by my breakpoint. Is there something like a maximum depth at which you can put breakpoints (that doesn’t make sense to me) but the behaviour is very strange.

I’m doing this within the Momentics IDE.

Any help would be greatly appreciated.

goloap

OK,

Debugging dll’s in the IDE, is not as easy as it could be. Here is what you need to do (this assumes that the program that loads the dll, and the dll reside in the same workspace):

1. In the debug configuration, you need to do several things
    a) On the "Download" tab, uncheck the "Do not download shared lib..",
        and add the dll (the _g variant!) you want to debug to the list of
        "shared libraries" to be downloaded (and deleted) automatically
        (stripping is OK).
    b) On the "Debugger" tab, select the "Shared Libraries" sub-tab, and
        add the path to the binary for the dll (on the host).  Make sure to 
        use a relative path, since having a driver letter in the path can 
        confuse gdb.  Since the dll should be in the same workspace use 
        ../{DLLNAME}/{CPU}/dll-g should work, if you haven't created 
        nesting from the project level.
     c) On the "Source" tab, add a "project" path to the location of the 
         source for the dll.
2. When you launch the debugger, you should break on main.  You need
    to set a breakpoint on the first dlsym(), in your program, and continue
    (play icon).
3. When the dlsym() breakpoint is hit, open the "Modules" view in the 
    debugger (i.e. Window->Show View->Modules).
4. In the modules view, there should be a module for your dll, right-click
    on the dll and select "Load Symbols".

At this point, you can now debug the dll, by opening the source files and clicking to set break points.

I have attached a completely functional workspace with a sample program and dll to this message, which might help…

Thank you very much. I was doing everything alright but I was using absolute paths, now with relative paths it works. Very strange behaviour.

I would have another debugging question for you. I have a timer interrupting using SIGUSR1 every millisecond and the program halts whenever it receives the SIGUSR1 while i was debugging something else.

For example, the program runs normally then the SIGUSR1 doesn’t halt the program, but then if a breakpoint gets hit and i say resume program (pressing F8 ) the program will suspend saying “Signal SIGUSR1 received …”. I don’t want to break when I get SIGUSR1. Do you know why this happens and how to stop the program halting for SIGUSR1.

Thanks again

Out of curiousity why use a timer signal combinaison. Depending on what you want to do why not use a thread/timer, or TimerTimeout ?

I’m currently porting an application that was designed to work on with only one thread. As such, after initializing the application monitors the keyboard for inputs and gets interrupted every millisecond to poll the communication ports. I know this is not the best way to do it, but currently my task is to make it work under QNX. Next step will be to convert it to used multiple threads.

Ok, I have a similar problem now but using a library that is built in another workspace. I cannot get the main application to find the library and load it’s symbols.

When I look in the Module view the Symbols file field is stated ast libName.so.1; while, the other librairies that load correctly have (FULL_PATH)/so-g/libName.so.1.

In addition, a previous library that was loading fine before doesn’t want to load anymore and i get the error message libName.so.1: No such file or directory. And the same thing appers in the Modules view. I guess this is a problem related to the path that I enter in “shared libraries” but I’m not sure from which directory I have to start the path if I use a relative path. i.e. is it …/(PATH) or …/…/(PATH) or any other combination.

Thirdly (not sure if that’s a word), when i start my program I get a few error saying "No source file named " (for 4 out of about 15 c files) But i specified the correct path in the “Source” tab in the Debug properties window.

I’ll keep trying, but tips would be very welcomed.

Also, if I use the option “download shared libraries to target” the library called LIB_g.so (because it’s the debug version) gets downloaded as “LIB.so.1” which means that my application can’t find it. Is this normal?

I’m getting increasingly confused about this process.

Found the reason for the last problem. It has to do with field “Library Shared Object Name”, I delete the default value and now it works. But now I’m back to my original problem (even though I used relative paths) which I will restate in case I wasn’t clear the first time.

I have 3 binaries:
mainExec (normal executable)
lib1.so (shared library)
lib2.so (shared library)

The general execution of the program is as follows

  1. Start in main of mainExec
  2. Load lib1.so and run its initialize function
  3. In the initizialize fct of lib1.so load lib2.so
  4. Execute the initialize of lib2
  5. Setup a 1ms, and then wait for inputs on console

Now the problem is that none of the breakpoints that I put in lib2.so ever get hit even though the code executed.

I feel like I’m talking to myself here, but that’s ok. I’ll continue doing it in case somebody runs in similar problems as me and gets any help from these postings.

After another few hours of head banging, I figured out that the problem actually resides in another place. In fact my 2nd shared library (lib2.so in the example above) consists of some code and a static library. And it is when I put breakpoints in the code of this static library that they don’t get hit. To make sure of this, I compiled the shared library with all the code of the static library also (so that I wouldn’t have to link it in) and now all the breakpoint work.

So I must be doing something wrong in the linking/debugging of the static library. I link the debug version of the static library by putting it in the Linker->Extra Object Files menu of my dynamic library. The code gets loaded correctly and i can see the source code. I just can’t set breakpoints in it. Do I have to include it somewhere else???

Anybody has an idea?