DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Coding
  3. Java
  4. Debugging the JVM

Debugging the JVM

Attila-Mihaly Balazs user avatar by
Attila-Mihaly Balazs
·
Jan. 11, 12 · Interview
Like (1)
Save
Tweet
Share
10.13K Views

Join the DZone community and get the full member experience.

Join For Free

in some (rare) cases you might find yourself in the situation that you managed to crash the jvm itself. i most recently managed this by setting the name of a threadgroup to null . in these cases it is useful to debug the jvm itself so that the crash can be located more precisely. here are the steps to do it (they are linux specific since there is no readily available debugger under windows):

  • install gdb (under ubuntu this would be something like: sudo apt-get install build-essential)
  • if you are using openjdk, install the debugging symbols for it so that the debugger can give a more readable output (again, under ubuntu this would be sudo apt-get install openjdk-6-dbg – substitute 6 with a 7 if you are using the latest openjdk)

now just prefix your java command with gdb --args:

gdb --args java foo

when the gdb prompt comes up (“(gdb)”), type “run” (without the quotes) to start the actual running of the program. after the crash happens you should a message like the following:

program received signal sigsegv, segmentation fault.
[switching to thread 0x6b195b70 (lwp 30273)]
(gdb)

here you can use the commands “backtrace” and “backtrace full” to get an approximate idea of the crashsite. to continue running (although it will just exit most probably) input “c”. to exit (killing the jvm in the process) type “quit”. consult the gdb tutorials available on the internet for more commands and their parameters.

if you are debugging from inside eclipse, you can do the following: in the configuration properties set the jre to “alternate jre” and specify the java executable as “javag” (also, make sure that you have “allocate console” checked in the common tab).

now go to your jdk run directory (/usr/lib/jvm/java-7-openjdk-i386/bin in my case) and create a javag file (sudo vim javag) with the following content:

#!/bin/bash
gdb -x '/usr/lib/jvm/java-7-openjdk-i386/bin/javag-commands' --args '/usr/lib/jvm/java-7-openjdk-i386/bin/java' $*

also create the javag-commands file with the following content

run

finally, make javag executable (sudo +x chmod javag) and you’re good to go! this workaround is necessary because eclipse doesn’t accept absolute paths in the configuration tab. the second file is used to automatically pass the “run” command to gdb rather than the user having to type it themselves on each start. also, keep in mind that while gdb has suspended the process java debuggers (like eclipse) can’t communicate with it so it is normal for them to throw all kind of errors (like “target not responding”).

have a bugfree year, but if you find bugs, let them be at least reproducible :-)

from http://www.transylvania-jug.org/archives/331

Java (programming language) Java virtual machine

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Top 5 Data Streaming Trends for 2023
  • File Uploads for the Web (2): Upload Files With JavaScript
  • How To Set Up and Run Cypress Test Cases in CI/CD TeamCity
  • Best Navicat Alternative for Windows

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: