Debugging my windows DLL that might be invoked from a Windows Service - c

I have my SNMP Extension Agent DLL that is called by the Windows SNMP Service (snmp.exe) everytime i do an snmpwalk (another console application) .I want to step into my DLL code that is called from the above Windows
Service. How do i go about doing that?
Thanks
Som

Normally, you'd attach your debugger to the running process that uses your DLL and then interact with the debugger as you'd normally do.
In Visual Studio 2008, you'd do that by using Debug > Attach To Process, then select the correct process. At least that's how I vaguely remember doing it before.

You can attach to running service from visual studio as Timo Geusch suggests. After that you can set a breakpoint in your code. You also can add call to DebugBreak function in the place you want to debug your library. This can help you if the code you want to debug is executed before you can attach to process (if your code executed in handler of service start event for example).
EDIT: You can attach to any service, even if you don't have debugging information for it, but in this case you wouldn't be able to see stack trace above your function call.

Related

How to debug C and Matlab code at the same time?

I have some Matlab .m files that use a C function I've created.
When Debugging in Matlab, or Visual-Studio, is there any way to run step by step both C and Matlab codes in a way that both Matlab a C variables remain usable for debug?
This addresses only the MSVS half of your question...
The steps to use step-by-step debugging using Visual Studio are outlined here. This is just an except centering around a .dll that is hosted by a pre-existing application. Matlab qualifies as a host application, whether it is also being run in debug mode, or not.
Start debugging from the calling app
The app that calls a DLL can be:
An app from a Visual Studio project in the same or a different solution from the DLL.
An existing app that is already deployed and running on a test or production computer.
Located on the web and accessed through a URL.
A web app with a web page that embeds the DLL.
To debug a DLL from a calling app, you can:
Open the project for the calling app, and start debugging by selecting Debug > Start Debugging or pressing F5.
or
Attach to an app that is already deployed and running on a test or production computer. Use this method for DLLs on websites or in web
apps. For more information, see How to: Attach to a running process.
Before you start debugging the calling app, set a breakpoint in the
DLL. See Using breakpoints. When the DLL breakpoint is hit, you can
step through the code, observing the action at each line. For more
information, see Navigate code in the debugger.
During debugging, you can use the Modules window to verify the DLLs
and .exe files the app loads. To open the Modules window, while
debugging, select Debug > Windows > Modules. For more information, see
How to: Use the Modules window. Use the Immediate window
You can [also] use the Immediate window to evaluate DLL functions or methods
at design time. The Immediate window plays the role of a calling app.
[and so on....]

How to debug C application using eclipse IDE under Linux

As you know,eclipse IDE has a convenient attached debugging facility for C project.You can see it from the GUI and you can use this facility to debug process that are already in running status,like daemon process..
My question is that when a process just started and I want to debug it from the begining of the process(i.e. from the first line of main function),how I can do it using the IDE?
I know under Windows,there is a tool called gflag,using this tool we can do some configuraitons before starting the process,and when the process is launched,the gflag can detect this and let the debugger tool(e.g. virtual studio) attach the process automatically.
Do not tell me that use sleep fuction.
Check CDT reverse debugging. You will need GDB 7.0 or later for this feature.
Refer
How_do_I_do_Reverse_Debugging
Open source code with eclipse and double click the left of line number to add a break point. Then you can create a session to debug your application

VS 2015 won't break at breakpoint in web api project

I have a VS2015 solution with 2 C# projects. A WPF client, and a Web API server. I set a breakpoint in the Web API code. Then ran the WPF client in debug. The breakpoint icons in the source file changed from solid red dots to red circles. The debugger is not breaking at the breakpoints. What am I doing wrong?
You effectively have 2 applications and you're trying to debug both at the same time which won't work.
Make your API run in IIS then use a separate Visual Studio instance to attach debugging to that process ( you can find it running under w3wp ).
So you can do this effectively with 2 instances of Visual Studio, one for the client and one for the API.
You can also simply open the same solution with a second VS, and run the API from there then have the client hit the api on the same URL as the one being debugged. It is a bit strange to use 2 Visual Studio instances but it does the job quite well.
Use whichever method you're more comfortable with.
I'm not 100% sure, but I think it is probably because you are just debugging the client. I had the same difficulty getting to the code of a WCF service recently. As I understand it (and I'm no expert, so people who know better feel free to correct me if I'm wrong) basically Visual Studio won't peek into the server code while you are just debugging the client. I presume that when you run the client, you also have the server running at the same time?
I think the best way to deal with this is either to start your client, and then attach the VS debugger to the server process (see https://msdn.microsoft.com/en-us/library/3s68z0b3.aspx), or to run both the client and server programs at the same time when you start the debugger (https://msdn.microsoft.com/en-us/library/ms165413.aspx).
Hopefully this helps :)

Debugging an app launched through scheduled tasks

How do I debug an application which is launched via scheduled tasks?
I have a simple application which works fine when double clicked to launch, but it doesn't work when launched through scheduled tasks.
I know how to debug projects on a local computer, but this application has no issues running on a local computer or on a different computer if launched manually by the user by double clicking the executable file.
I need a way to debug the application when it's being launched by scheduled tasks. Is this possible?
I would primarily suggest putting in some decent logging so that you can diagnose problems without resorting to the debugger. However, to launch the debugger, you can either attach it to an existing process in Visual Studio (using Debug/Attach to process... menu), or change the code to include the Debugger.Launch() method which will launch the debugger and attach it to the process. Of course all of this is dependent on your program actually being executed by the scheduler. If the scheduler doesn't execute the program, then the debugger obviously can't attach to it

How to handle win32 services in windows 2000 platform

I ve designed a win32 service in windows XP its working fine. but the problem i'm facing is that it's not working properly in windows 2000 platform. that is stopping the service restarting the service. is there any setting or need to change in code to be done.
Is it possible you have used an API that was new on WinXP?
For an interactive applications you would get a popup about an unresolved import, if I recall correctly for services these are recorded in the system event log.
If it is hanging, take process dumps and feed them into a debugger with symbols (both Microsoft's and yours) configured. That will show you the stacks of the threads, and allow you to check for deadlocks.

Resources