Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6812473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:27:12+00:00 2026-05-26T20:27:12+00:00

how do you execute gdb commands using process object in java? charmae@charmae-pc:~/Desktop$ gcc -g

  • 0

how do you execute gdb commands using process object in java?

charmae@charmae-pc:~/Desktop$ gcc -g file.c
charmae@charmae-pc:~/Desktop$ gdb ./a.out
GNU gdb (Ubuntu/Linaro 7.3-0ubuntu2) 7.3-2011.08
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/charmae/Desktop/a.out...done.
(gdb) run
Starting program: /home/charmae/Desktop/a.out 
address of x = 0xbffff2f8
address of y= 0xbffff2fc
address of x = 0xbffff2f8
value of x = 1
[Inferior 1 (process 4268) exited with code 017]
(gdb) 

In my java code:

 Runtime rt = Runtime.getRuntime();
 Process proc = rt.exec("gdb ./a.out");
                rt.exec("run");
 BufferedReader std = new BufferedReader(new 
                     InputStreamReader(proc.getErrorStream()));
 while ((s = std.readLine()) != null) {
                 System.out.println(s);
               }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:27:13+00:00Added an answer on May 26, 2026 at 8:27 pm

    Yey! Answered my own question.. i used pipe processing.

        public class GDBpipeWriter extends Thread{
    
            public void run(){
            Process p = null;
            try {
            p = Runtime.getRuntime().exec("gdb a.out --interpreter=console");
           new Thread(new SyncPipe(p.getErrorStream(), System.err)).start();
           new Thread(new SyncPipe(p.getInputStream(), System.out)).start();
            PrintWriter stdin = new PrintWriter(p.getOutputStream());
    
            stdin.flush();
            stdin.println("break 4");
            stdin.flush();
            stdin.println("break 10");
            stdin.flush();
            stdin.println("run");
            stdin.flush();
    
            /// write any other commands you want here
           // stdin.close();
    
    
            } catch (Exception e) {
                e.printStackTrace();
            }
            }
        }
    
    
    class SyncPipe implements Runnable
    {
    public SyncPipe(InputStream istrm, OutputStream ostrm) {
          istrm_ = istrm;
          ostrm_ = ostrm;
      }
      public void run() {
          try
          {
              final byte[] buffer = new byte[1024];
              for (int length = 0; (length = istrm_.read(buffer)) != -1; )
              {
                  ostrm_.write(buffer, 0, length);
              }
    
          }
          catch (Exception e)
          {
              e.printStackTrace();
          }
      }
      private final OutputStream ostrm_;
      private final InputStream istrm_;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to execute a shell command from a java application, on the GNU/Linux
Is there a way to execute function in process core context in GDB? The
I am trying to execute two commands at once in gdb: finish; next I
I execute the ftp.exe cmd through a C# System.Diagnostics.Process type. And I use the
To execute a loop in parallel I am using: int testValues[16]={5,2,2,10,4,4,2,100,5,2,4,3,29,4,1,52}; parallel_for (1, 100,
I'd like to write a script that (under certain conditions) will execute gdb and
I'm using pthread_cond_timedwait on a thread loop to execute at every X ms (unless
I need to debug a certain set of commands each time i invoke gdb
I would like to execute the following command : ndk-gdb --help, in the console
I made a cross compiling toolchain for arm-gcc, configuring binutils, newlib, gcc and gdb

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.