How to debug child project process in Visual Studio - visual-studio-debugging

I have a solution with two console applications. Application B is started by application A. I would like to debug both, but at least application B.
I have tried to configure as debug profile for application B to start executable A instead of itself, and I have set up application B to be the startup project. When I hit Run application A is started as expected, which in turn starts application B, however I still get the warning on my breakpoint in application B that it won't be hit because the source code is different. I have tried to set dependency of A from B, and also of B from A, but neither made any difference.
Update: However, attaching to the already running process B works as expected. This can be a workaround but a quite cumbersome one.
What can be done to get this right?

What can be done to get this right?
Please try to use the Child Process Debugging Power Tool which is also suitable for VS2019.
We can easily debug this child project with this extension by Debug-->Other Debug Targets-->Child Process Debugging Settings.(If you are debugging .NET code, you must choose to enable mixed mode debugging which means that you debug two different types of projects.)
In the pop-up page, check the box to open the startup child process debugging and click Save. After that, default debug will support all child processes.
Note that by default, the same debug engine settings are used as the parent process debug.
More information you could refer to this blog. Hope it could help you.

Related

Using lldb on mac os doesn't ask for Developer Tools Access

I'm following a tutorial on using lldb. I tried typing process attach -p and I got error: attach failed: Error 1. However in the tutorial a screen pops up asking for "developer tools access needs to take control of another process for debugging to continue". I think this is why it won't work. Why does it not pop up?
What were you trying to debug? On Darwin systems, only processes that opt into being debugged can be, and most shipping apps (including all the system ones) do not opt into being debugged.
Since this isn't an issue with the general permission to debug, but rather the target proces rejecting your attach attempt, you wouldn't see the "Developer Tools" dialog box. You machine is configured to debug, just not this process...
You can test this by building something yourself and then attaching to it.

How to debug a code on Logic-Apps?

I'm using Logic-Apps for my project now. I think it's good and easy! However, It was difficult to debug during the coding of the logic. Because I couldn't to confirm the variables or status at a middle point of the code. Usually a developer can detect the variables during the execution of program on Visual Studio. How can I debug the code on Logic-Apps? Do you have an idea?
At the moment, Logic Apps can only run on Azure, thus while you are developing a workflow, in order to debug your code, you need to run it on Azure. Once you run it, you can see the inputs and outputs of each action for that instance, including setting variable actions.
You can see in the documentation how to monitor each instance and the inputs and outputs of each action.
HTH

Qt using gdb to debug an attached process

Environment
Qt 5.6.1
Qt Creator 4.0.1
gdb 7.11
Ubuntu 16.04 LTS
Scenario
C: A client application to communicate with M.
M: A manager process to notify L to launch a new process T.
L: A Launcher process to launch new T by forking itself.
T: A new process running in the background.
I am able to run test application and debug the process C in Qt with gdb. But I am not able to debug the T.
Here is the way I tried to debug the T:
Set breakpoints in both C and T;
When the breakpoint is hit. I use Qt menu option "Debug"->"Start Debugging"->"Attach to running application". To try to attach the debugger to the T process.
This is the problem I am having
Instead of hitting the breakpoints that I set in the T. The gdb always hit an invisible breakpoint in function epoll_wait(). After that, if I continue (F5). The application will keep hanging without hitting any further breakpoints in T. Unless I force stop by using the Qt debug option "Stop Debugger". The application is keep waiting. After I stopped the debugger, the C still breaks in the original breakpoint.
The problem with the debugger in Qt
It seems that Qt uses two different debuggers for different processes. I am thinking it might be caused by the C is hanging. So the T process is keep waiting. But I did not set any breakpoints in wrap_epoll_wait() function I am not sure why gdb breaks there. And in the Qt Debugger. I cannot find a way to switch back to C process to let the process to continue to run. (The Qt debugger component "Threads" drop list is disabled by some reason, I can not select a different thread).
The things I tried
Modified the /etc/sysctl.d/10-ptrace.conf set kernel.yama.ptrace_scope value to 0
Turned the debugger option "Tools->Options->Debugger->GDB Extended->Debug all children" on and off in the Qt.
None of above things changed the fact that the debugger is hanging after the debugger breaks in the function wrap_epoll_wait().
My Question
Anyone at good gdb and Qt knowledge could help me? And let me know how the gdb debug multiple processes works in Qt? How to switch the debugger between different processes and why gdb breaks on somewhere I did not set the breakpoint?
Thank you very much,
Rong
Since T created by forking from L. The gdb settings 'set follow-fork-mode' needs to be set to 'child' in Qt creator.
reference:
https://sourceware.org/gdb/onlinedocs/gdb/Forks.html

Execute a c program as a background process

I am trying to make a background process in C to disable the visibility of the output/execution window. I used the following code but on using this the antivirus software reporst it as a threat and generates warnings:
HWND stealth;
AllocConsole();
stealth=FindWindowA("ConsoleWindowClass",NULL);
ShowWindow(stealth,0);
details are :
language : c
compiler : dev cpp
platform : windows 7/8
Is there any way I can create a background process in C without antivirus alerts?
If you just want an application that runs in the background without showing a console window, then the solution to your problem is far simpler: just don't create a console window!
Now, easier said than done. You've presumably created a Console application using the template in Visual Studio or some other IDE. This causes the application to be flagged when it is built as a Console application, and such applications always have a console window allocated to them on startup.
You don't want that, so you need to indicate that your application is not a Console application. In fact, it is just a regular Windows (Win32) application that doesn't show any windows. When writing a standard Windows application, no windows are created by default. If you don't create them in your code, then nothing gets created or displayed. And that's exactly what you want for a background process.
How you make this magic happen depends on your compiler/linker/IDE. Assuming you are using Visual Studio, you can follow these steps:
Right-click your project in the Solution Explorer.
Open the "Linker" category in the left-hand tree.
Select the "System" item in the tree.
Change the "Subsystem" setting to Windows, rather than Console.
That will automatically set the /SUBSYSTEM linker flag to specify WINDOWS, rather than CONSOLE.
(Edit: I just noticed that you said you're using Dev CPP. I've never used that IDE, but according to the directions I find online, you can just set the target to "GUI" in your project options. That should cause the -Wl,-subsystem,windows switch to be set when the linker is called. If not, find the linker flags in your project options and ensure that that switch is being passed.)
You will also need to take the final step of changing your application's entry point. Console applications have an entry point named main. For Windows applications, it is named wWinMain and has the following signature:
int WINAPI wWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PWSTR pCmdLine,
int nCmdShow);
You should be able to simply change the signature of your main method to the above signature for wWinMain and be off to the races.
If you don't want to do it the right way, there is still a better option than what you're currently doing. Instead of issuing suspicious-looking commands to hunt around, look for a process, and hide its windows (just smacks of malware, doesn't it?), you can simply deallocate the console window that is automatically created for your application. To do that, call the FreeConsole function.
It takes no parameters, because a process can only ever be attached to one console. You don't need to tell it what to free because there is only one possibility. The console window will automatically be closed when it has been detached from all processes—if your application is the one that created it and the only one that was attached to it, that means it'll close automatically.
If you need a console window again for some reason, you can call AllocConsole.

Parent window not receiving window's messages (Key Events)

I have a GUI application that is written using win API's
and we need to launch a new GUI application when the user selects some command menu items.
We decided to write the new application in PyQt and launch the PyQt application usig Python C Api.
Everything is working fine except that the Parent window, through which we launch the PyQt Application, is not responding to some of the events when PyQt application is open. Once we close the PyQt Application it starts responding again to the key events.
I guess, that once the PyQt Gui application is launched, somehow the messages are not passed to the Parent window.
Inspecting with Spy++ I've found the following result:
Receives messages for:
- ALT key
- F1, F2 keys
- Mouse events
Does NOT receive messages for:
- CTRL key
- All other Fn keys
- All letter keys
- SHIFT, CAPS keys
Any thoughts to solve this problem would be appreciated
I believe what you are trying to do -- operate two separate GUIs within a single process -- is not supported by any major operating system. A while back, I searched for a long time for ways to do this and never came up with any advice except "don't".
I'm surprised that missing keys are the only problem you have.. I recommend finding a different solution before you discover more trouble (unless you can find some good evidence that this is at least supposed to work).
Could you perhaps spawn a new process to run the Qt event loop instead? Since you already have python embedded in the main process, this should be fairly easy--use python's built-in IPC to handle the communication between processes.
One solution is to build the QtWinMigrate module to create a QWinHost which supports parenting to a native HWND but unfortunately it is not part of the PyQt distribution.
You can find some sources here: https://github.com/glennra/PyQtWinMigrate.
This is what had to be done for Python integration in 3ds Max by Blur studio. I am currently studying the C++ source code of QWinWidget too see if I can work out an alternative solution using Win32 calls.

Resources