Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to set a breakpoint in code

How to set a breakpoint in code

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingjsontutorialquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Soundman32 2
    wrote on last edited by
    #1

    I am dynamically loading a second process (via CreateProcess) and would like to automatically set breakpoints in that process. VS2005 doesn't automatically set the breakpoints even though the code I want to break on exists in both projects. Is there an API I can call to set a breakpoint on a function in another process?

    J 1 Reply Last reply
    0
    • S Soundman32 2

      I am dynamically loading a second process (via CreateProcess) and would like to automatically set breakpoints in that process. VS2005 doesn't automatically set the breakpoints even though the code I want to break on exists in both projects. Is there an API I can call to set a breakpoint on a function in another process?

      J Offline
      J Offline
      JudyL_MD
      wrote on last edited by
      #2

      After it is started via the CreateProcess, fire up another instance of VS2005 and "attach" to the just launched process. You can set breakpoints now. If you need to debug the process's startup code, use DebugBreak and connect VS2005. I've always used a new instance of VS to debug each different process - don't know if you can do multiple processes all in one. Judy

      S 1 Reply Last reply
      0
      • J JudyL_MD

        After it is started via the CreateProcess, fire up another instance of VS2005 and "attach" to the just launched process. You can set breakpoints now. If you need to debug the process's startup code, use DebugBreak and connect VS2005. I've always used a new instance of VS to debug each different process - don't know if you can do multiple processes all in one. Judy

        S Offline
        S Offline
        Soundman32 2
        wrote on last edited by
        #3

        Ah, but that's the problem. By the time I can click on Attach To Process and then select the process and press Attach, the program I'm trying to trap has already run the function I want to trap. I can't modify the source to the program I want to attach to. I need to find a way to set breakpoints in the launched process via the application I am writing. Something like: { CreateProcess("newprogram.exe", ... CREATE_SUSPENDED, ... ); SetBreakpoint(newProcessHandle, "FunctionToDebug"); ResumeProcess(newProcessHandle); }

        J J 2 Replies Last reply
        0
        • S Soundman32 2

          Ah, but that's the problem. By the time I can click on Attach To Process and then select the process and press Attach, the program I'm trying to trap has already run the function I want to trap. I can't modify the source to the program I want to attach to. I need to find a way to set breakpoints in the launched process via the application I am writing. Something like: { CreateProcess("newprogram.exe", ... CREATE_SUSPENDED, ... ); SetBreakpoint(newProcessHandle, "FunctionToDebug"); ResumeProcess(newProcessHandle); }

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #4

          Soundman32.2 wrote:

          By the time I can click on Attach To Process and then select the process and press Attach, the program I'm trying to trap has already run the function I want to trap.

          In your processes code, call DebugBreak(), and the code execution will stop and you will be given the chance to attach a debugger.


          Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
          George Orwell, "Keep the Aspidistra Flying", Opening words

          1 Reply Last reply
          0
          • S Soundman32 2

            Ah, but that's the problem. By the time I can click on Attach To Process and then select the process and press Attach, the program I'm trying to trap has already run the function I want to trap. I can't modify the source to the program I want to attach to. I need to find a way to set breakpoints in the launched process via the application I am writing. Something like: { CreateProcess("newprogram.exe", ... CREATE_SUSPENDED, ... ); SetBreakpoint(newProcessHandle, "FunctionToDebug"); ResumeProcess(newProcessHandle); }

            J Offline
            J Offline
            JudyL_MD
            wrote on last edited by
            #5

            That's a tough one without being able to modify the source of the target. Just to make sure you haven't missed the obvious, have you tried to Attach after the process is created in the suspended state? I don't expect it to work, but I personally don't know what else to try. You're down to the point of having to do something to modify the target. If you can't touch the source, the only thing left is modifying the asm code in the .exe file. Can't help there. Sorry, Judy

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups