Can I Attach to Process without it being already running? - visual-studio

Using Visual Studio 2005's Attach to Process, is it possible to select an application to run and then debug as opposed to an application that is already running?
I am trying to debug a FileMaker Plugin and I can debug it fine if I open FileMaker then use attach to process, but I now want to debug the initialisation of the plugin so need to debug as soon as the host application starts.
Is this possible?

using F5. Drag and drop the exe file to Studio and then start Debug. You can launch the exe from Visual Studio itself and provide the dll names in "additional dlls"

For a VS project you can easily specify the command to be executed in the Debug section of the project properties. You have not specified what language you're using but AFAIK you can specify the debug command in all of them.
For C++ this is located in the Debugging section, the property is Command.
For C# under the Debug Tab, specify the external application to start.

Absolutely. I've had success with the method posted here and the Windows Debugging Tools.
You can also launch the process from your code and use Debugger.Attach to launch the debugger dynamically.
There is also a Visual Studio plugin that will handle this for you.

Related

How to I open a file when I start debugging in Visual Studio?

I'm making a WinUI3 app in Visual Studio, and I'd like to open a file when I start debugging, so that activatedEventArgs.Kind == ExtendedActivationKind.File as per this.
I'm really struggling to turn anything up with google, so am making a question here to help the next person.
Assuming that you already registered your file type (by following the steps in the link you provided) and your target app is already deployed (when run on VS),
you can debug it this way:
In VS, go to Debug > Other Debug Targets > Debug Installed Debug Package...
Select your app in Installed App Packages.
Select Managed(.NET Core, .NET 5+) in Debug this code type.
Check Do not launch, but debug my code when it starts.
Click Start. (The debugger starts running without launching your app.)
Double-click your target file. (Your app launches and the VS attaches the debugger to you app).

Assign executable file name for debug session (Visual Studio 2019)

We have a legacy Visual Studio 2003.NET C++ DLL project. Still works with VS2003 on Windows 10 but we're looking to migrate to VS2019.
In VS2003 when you debug (F5), the box Executable for Debugging Session pops up. In the Executable file name box you select Browse... and navigate to the .EXE which will consume your DLL. Great!
But how to do the same in VS2019? Whenever I debug, Visual Studio thinks I'm using the Local Windows Debugger and I get the error "[PATH][PROJECT].dll is not a valid Win32 application". The Debug > Attach to Process... option is not right either because my target executable is not running yet.
If I'm understanding the problem correctly, I think you want to select the Debugging section of your DLL project's property pages. There you can choose which debugger to use and you can even set the executable you want to launch.

Debugging an executable in visual studio

Want to debug an executable under debugger. How to do it in visual studio.
Windbg has an option of open executable. But I find this is missing in VS 2010.
The question is not exactly same as
Debug exe in visual studio 2010
as I am not really interested in image file execution to debug a start up.
Rather want to just debug the exe under debugger, once it is broken, want to
set some break points and understand the flow of execution.
Albeit image file execution is a workaround for this.
I am not sure if this question is naive; But this is a very straight line use case scenario, I find missing in MS VS 2010.
You did not specify it in the question, but I assume you do not have the source code. Just use File/Open Project/Solution, select EXE file and Open it. Then select Debug/Start debugging. The other option is to run the EXE first and then Select Debug/Attach to process.
If what your asking is how do you attach VS to the exe you want to run then you can follow these steps:
Run the executable
In VS navigate to Debug -> Attached to Process
Find your process created by running your executable and click "attach".
However, if the executable you are trying to run fails almost immediately or runs quickly and exits then you could try the following steps:
Set a debug point at the start of the code
Switch your build to Debug and run the application.
If your application is running in Debug, but failing when you execute the exe then you could try these steps to see if the your app will give more information in a console window or other.
Make sure your build is set to Release.
Navigate to Debug -> Start Without Debugging
If you have the source code, you can use Debugger.Launch();
You put it anywhere in your code, build the .exe and then once it gets launched (by Process.Start for example) and reaches Debugger.Launch();, a window will be asking you how you want to attach to the process.
Typically, you'll attach to some Visual Studio instance and it'll automatically pause the debugger where Debugger.Launch(); has been placed.
You can then open the project's files (File -> Open -> File...) and place breakpoints wherever you want.

How to debug VS2010 setup project?

How to debug VS2010 setup project? I tried attaching to msiexec.exe , but it didn't help.
I am assuming you want to debug a custom action in the installer. If so having the solution open while running the installer and have this line of code in one of the events.
System.Diagnostics.Debugger.Launch();
When prompted say yes to debug the installer and select the instance of Visual Studio with your project already loaded.
It appears that I need to halt my managed code so the process will appear in the debug window. It can be done by calling MessageBox.Show. After that the msiexec managed code entry appears in the processes and if I attach to it I will be able to debug my custom actions code.

Debugging with 'Attach to Process' magic with Visual Studio 2010/Xcode/gdb

I see that with the 'Attach to Process', one can debug the process by setting up break point in Visual Studio IDE.
I think it's pretty cool, and I'm curious what's the mechanism that enables it. I also found that gdb and Mac's Xcode supports the technology.
Q1 : Can anyone explain how does this work? How can the process mapped to a breakpoint in an IDE or gdb environment?
Q2 : Are there other compiler/debugger options than /Zi or -g (adding debug info)?
Q3 : Is this the way to debug dll (dynamic library)?
ADDED
I found this one with MSDN - http://msdn.microsoft.com/en-us/library/c6wf8e4z.aspx
The most common scenario I know of is using a browser to debug web code. In these cases, you start Visual Studio in debug mode and then attach to the browser and call the page in question. When the page is called it starts running the code in the debugger. Essentially, the debugger watches the process and when it hits code in VS, it starts debugging.
The same is true with other applications that are calling code you are running in Visual Studio. When you cross the boundary to the code, the debugger catches the call and starts running code in VS.
I use it fairly frequently when developing plugins for existing applications (Maya, Reaper, etc). As a general rule, plugins can't be run independently, so in order to debug them I have to run the host program and use "Attach to Process" to run the debugger on my plugin, at which point I can set breakpoints and all that other debugging goodness. You need to have debugging symbols and al that for the plugin, but you don't need to have them for the host application.

Resources