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 do I debug a dll which is used by java?

How do I debug a dll which is used by java?

Scheduled Pinned Locked Moved C / C++ / MFC
questiondebuggingcsharpjavavisual-studio
5 Posts 2 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.
  • I Offline
    I Offline
    IlanTal
    wrote on last edited by
    #1

    I'm using Visual Studio and wrote a HelloWorld dll which runs under java, using JNI. If I use the command prompt, it works: C:\Ilan\OsnatFunc\Debug>java osnat.HelloWorld Hello World Now I want to use Visual Studio to put a break point and debug it. (In this simple case there is nothing to debug, but there will be a next step.) I assume it should be something under the Property Pages, with Debugging, probably with Command or Command Arguments. I have tried "java osnat.HelloWorld", but that isn't correct. The question is: what do I use to operate my java project as a main, which will then call the dll where I have my breakpoint? Thanks, Ilan

    J 1 Reply Last reply
    0
    • I IlanTal

      I'm using Visual Studio and wrote a HelloWorld dll which runs under java, using JNI. If I use the command prompt, it works: C:\Ilan\OsnatFunc\Debug>java osnat.HelloWorld Hello World Now I want to use Visual Studio to put a break point and debug it. (In this simple case there is nothing to debug, but there will be a next step.) I assume it should be something under the Property Pages, with Debugging, probably with Command or Command Arguments. I have tried "java osnat.HelloWorld", but that isn't correct. The question is: what do I use to operate my java project as a main, which will then call the dll where I have my breakpoint? Thanks, Ilan

      J Offline
      J Offline
      James R Twine
      wrote on last edited by
      #2

      In order to debug something, the debugger has to attach to whatever process contains the code you are interested in.  In the case of DLLs, this means the process that is loading the DLL, and in your case, it sounds like whatever process contains the JVM.    I would suggest trying to find the process that is actually loading your DLL (and running your Java code that calls into it) - if you cannot do this easily, a quick but kludgy way is to write some in the load-time code of your DLL that causes a spin for 15 seconds, allowing you to locate the spinning process in Task Manager, thus identifying the process you need to attach the debugger to.    Peace!

      -=- James
      Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
      Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
      See DeleteFXPFiles

      I 1 Reply Last reply
      0
      • J James R Twine

        In order to debug something, the debugger has to attach to whatever process contains the code you are interested in.  In the case of DLLs, this means the process that is loading the DLL, and in your case, it sounds like whatever process contains the JVM.    I would suggest trying to find the process that is actually loading your DLL (and running your Java code that calls into it) - if you cannot do this easily, a quick but kludgy way is to write some in the load-time code of your DLL that causes a spin for 15 seconds, allowing you to locate the spinning process in Task Manager, thus identifying the process you need to attach the debugger to.    Peace!

        -=- James
        Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
        Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
        See DeleteFXPFiles

        I Offline
        I Offline
        IlanTal
        wrote on last edited by
        #3

        How does one normally debug a dll? I agree one has to start the process which calls the dll. In my case the process is the JVM. "java osnat.HelloWorld" starts this process under the command box. I assume there should be some way to start it under the Visual Studio debug mode? If I really have no other choice, then I could try to attach to a process that is in some loop, but I hope there is a more direct method. Ilan

        J 1 Reply Last reply
        0
        • I IlanTal

          How does one normally debug a dll? I agree one has to start the process which calls the dll. In my case the process is the JVM. "java osnat.HelloWorld" starts this process under the command box. I assume there should be some way to start it under the Visual Studio debug mode? If I really have no other choice, then I could try to attach to a process that is in some loop, but I hope there is a more direct method. Ilan

          J Offline
          J Offline
          James R Twine
          wrote on last edited by
          #4

          Yes, the "executable for debug session" will be the full path to the java executable, and the program arguments would be (the full path to?) osnat.HelloWorld.    I would think that would do it.  Note that you are not normally able to set breakpoints in a DLL until the DLL has been loaded by the debugger, which usually happens the first time the process-being-debugged loads the DLL.    Peace!

          -=- James
          Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
          Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
          See DeleteFXPFiles

          I 1 Reply Last reply
          0
          • J James R Twine

            Yes, the "executable for debug session" will be the full path to the java executable, and the program arguments would be (the full path to?) osnat.HelloWorld.    I would think that would do it.  Note that you are not normally able to set breakpoints in a DLL until the DLL has been loaded by the debugger, which usually happens the first time the process-being-debugged loads the DLL.    Peace!

            -=- James
            Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
            Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
            See DeleteFXPFiles

            I Offline
            I Offline
            IlanTal
            wrote on last edited by
            #5

            James thanks, This turns out to be messy. I couldn't figure out how to put the command (with full path?) once and for all into the command line. Up would come a message box and if I have to enter full path each time, I might just as well attach to a process. Up until now I've always used c++ and it was simple to put the break point in the calling routine and then just step into the routine under the dll. With java I first thought maybe I could use a get character from keyboard to trap it and then attach to the process, but then I remembered the old int 3, which may do the job for me. (In any case I have to recompile the dll with a one line change when I want to debug it.) Int 3 is now __debugbreak(), but it does the job. Up comes a message box telling me my program has crashed and if I want to send a report to Microsoft? There is a debug button which allows me to attach a debugger, which is what I wanted to do in the first place. In short, this looks like the easiest solution. You asked me to reply if your suggestion helped. I couldn't reply so long as I didn't have a solution. You should be aware that even your offer to help is of great value. It gives additional thought for consideration which is always of great value when you are stuck with only your own way of thinking. So, if you helped? I think the answer is always YES! Thanks. Ilan

            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