Debugging DLLs lazarus / 12-Debugger ---------------------------------------------------------------------- CWBudde · 2006-08-08 15:47 While trying to fix Bug 7182 (see http://www.freepascal.org/mantis/view.php?id=7182), I used the debugger to set breakpoints. After some changes, I am now unable to use the debugger again. I tried to uninstall everything and reload/install the whole stuff again, but each time I add debug information (-g or -gl) the DLL seems to be not valid. The debug output is: Code: [Select](gdb) &"Warning:\n" &"Cannot insert breakpoint 2.\n" &"Error accessing memory address $110f: Input/output error.\n" &"\n" ^error,msg="Warning:\nCannot insert breakpoint 2.\nError accessing memory address $110f: Input/output error.\n" (gdb) And if I run the project (I specified a host application to run the DLL), nothing happens. If I stop the project and run again, it works fine except the fact, that any breakpoint is ignored. If I remove the breakpoints or don't include debug information, everything works fine from the start (except that I do not have the ability to debug). Hint: If I compile with debug information, UPX is unable to pack the EXE (regardless if I strip the file or not). Furthermore the Checksum in the PE header is wrong (=0!). I've tried nearly every option (including smart linking, internal linker for FPC 2.1.1 ans FPC 2.0.4) Any ideas? Christian ---------------------------------------------------------------------- Phil · 2006-08-08 17:06 Quote from: "CWBudde"I tried to uninstall everything and reload/install the whole stuff again, but each time I add debug information (-g or -gl) the DLL seems to be not valid. I've also noticed sometimes that DLL's compiled with -gl crash when called. What version of FPC are you using? FPC 2.0.2 doesn't seem to have this problem, but 2.1.1 does sometimes. I haven't tested the current snapshots' FPC 2.0.4 for this issue. I've posted a lot of bugs related to DLL's and 2.1.1. A few have been fixed but the more serious ones have not been. Thanks. ---------------------------------------------------------------------- CWBudde · 2006-08-08 19:08 Quote from: "Phil"What version of FPC are you using? FPC 2.0.2 doesn't seem to have this problem, but 2.1.1 does sometimes. I haven't tested the current snapshots' FPC 2.0.4 for this issue. I used version 2.0.4 and it definitely worked with 2.0.4 once. I hadn't got lazarus installed on this machine, so I downloaded the latest Lazarus snapshot. It is bundled with 2.0.4 since some days. Then I downloaded your example. It worked fine out of the box (although i had to reset the FPC path as far as I remember). I found out a problem with ShowModal, so I focused on that problem first. Meanwhile I tried the same thing with FPC 2.1.1 to see if it had the same problem. After I switched back I was no longer able to debug. Even a complete reinstall didn't solve the problem. I may try it on my notebook later tonight, but there Lazarus is also already installed. Quote from: "Phil"I've posted a lot of bugs related to DLL's and 2.1.1. A few have been fixed but the more serious ones have not been. I hope that these will be fixed. I need to implement some DLLs in october for a third party product (I don't have the code of the host application) and I'd like to do that with lazarus. Right at the moment it is nearly impossible. There are far too many bugs and if the debugger doesn't work correctly it's hard to fix any of these bugs. I still do have some time, but I fear there won't be too much changes until october. Sorry for the rather long post, Christian ---------------------------------------------------------------------- Vincent Snijders · 2006-08-08 19:52 I am not sure you tried this, so I tell, just in case: for fpc 2.1.1 debug info is better, if you use the external linker. On the custom compiler options tab, add -Xe. ---------------------------------------------------------------------- Phil · 2006-08-08 20:11 Quote from: "CWBudde"Then I downloaded your example. It worked fine out of the box Are you saying that you were able to get a form to run within a DLL? I haven't seen that working yet. When working with code that will go into DLL's, we usually debug by compiling the units that the DLL uses into a console app and debugging that. That's easier than trying to debug a DLL. The "library" file then is just a very small file where the DLL functions are exported. You can also use something like this in a console app:     try     except {$IFDEF FPC}       WriteLn(BackTraceStrFunc(ExceptAddr)); {$ENDIF}       raise;       end; If the code raises an exception, this code prints out the backtrace. I don't think this works in a DLL. ---------------------------------------------------------------------- CWBudde · 2006-08-08 20:58 Quote from: "Vincent"I am not sure you tried this, so I tell, just in case: for fpc 2.1.1 debug info is better, if you use the external linker. On the custom compiler options tab, add -Xe. Thanks for the info. I will try this ASAP. Right now I crashed my lazarus completely. I was trying to use the latest SVN version, but I must have done something wrong. FPC couldn't find the 'contnrs' in 'graphics' anymore. I believe that I've seen this some time ago, but I was unable to fix it. Now I'm trying my luck with the latest 2.0.4 snapshot. ---------------------------------------------------------------------- CWBudde · 2006-08-09 00:31 Quote from: "Phil"Are you saying that you were able to get a form to run within a DLL? I haven't seen that working yet. When working with code that will go into DLL's, we usually debug by compiling the units that the DLL uses into a console app and debugging that. That's easier than trying to debug a DLL. The "library" file then is just a very small file where the DLL functions are exported. I was not only able to get a form to run from within a DLL (except the bug that it is not responsible), but I was also able to debug this DLL. With the -Xe switch I havn't got any more luck than with every other option. This damn compiler/debugger bug is blocking the whole bug fixing process. If only I understand how FPC works. Now I make a new FPC bug report, maybe someone over there may found some time for it, Christian ---------------------------------------------------------------------- CWBudde · 2006-08-09 03:09 I now can debug DLLs again. The limitation is, that the breakpoint must be inside the LCL stuff! I always tried it in the DLL code. So blame it on me and not the FPC team. Anyway it's still a bug, so it can't hurt to keep the bug posted on the FPC site. Furthermore I think I found the reason for Bug 7182. But before I mess up everything again I take some sleep now... Christian [EDIT]Knowing the reason does't fix the bug. So far I found out, messages can not get throught to the active window. However I do not know a solution to fix it. PeekMessage() seems to cancel every relevant message out :-( But the whole thing isn't related to Debugging DLLs anymore. So thank you for all the suggestions! [/EDIT]