LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-16-2010, 06:13 AM   #1
ufmale
Member
 
Registered: Feb 2007
Posts: 386

Rep: Reputation: 30
debug in eclipse as root


Can I debug my code as root in eclipse without starting the eclipse as root? I searched on the net, and seems like it is not possible.
 
Old 06-16-2010, 08:10 AM   #2
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Why do you need to do that? Does your program do something privileged? If so, you could always compile it, `chown root $prog && chmod u+s $prog' it, add code at the start to call suid(2) with an argument of 0, then debug...?
 
Old 06-18-2010, 01:26 AM   #3
ufmale
Member
 
Registered: Feb 2007
Posts: 386

Original Poster
Rep: Reputation: 30
Could you elaborate the "suid(2) with an argument of 0"?

Yes the code needs to get cpu information/speed. I ran it with normal user and get error.

An how to set the compilation within the eclipse? I am using eclipse in Fedora.
 
Old 06-18-2010, 03:38 AM   #4
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Sorry, that should have been setuid(), not suid().

On Unix-like systems, you can set an executable to "be suid" like so:

Code:
$ ls -l
total 0
-rwxr-xr-x 1 john john 0 2010-06-18 09:32 program
$ chmod u+s program
$ ls -l
total 0
-rwsr-xr-x 1 john john 0 2010-06-18 09:32 program
Notice the user portion of the permissions changed from rwx to rws - that means the kernel will allow the program to call setuid() to change the uid to the owner of the program - if you make root own the program, then it can call:

Code:
setuid(0);
and suddenly it's running as the root user. This is how programs like passwd and sudo let you gain root privileges.

I don't know how you'd do that under Eclipse, but there's probably an option somewhere to run a custom command after compilation. Or just do it yourself - let Eclipse compile, you change owner and make it setuid, then you get Eclipse to run/debug.
 
Old 06-18-2010, 01:09 PM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by JohnGraham View Post
Sorry, that should have been setuid(), not suid().

On Unix-like systems, you can set an executable to "be suid" like so:

Code:
$ ls -l
total 0
-rwxr-xr-x 1 john john 0 2010-06-18 09:32 program
$ chmod u+s program
$ ls -l
total 0
-rwsr-xr-x 1 john john 0 2010-06-18 09:32 program
Notice the user portion of the permissions changed from rwx to rws - that means the kernel will allow the program to call setuid() to change the uid to the owner of the program - if you make root own the program, then it can call:

Code:
setuid(0);
and suddenly it's running as the root user. This is how programs like passwd and sudo let you gain root privileges.

I don't know how you'd do that under Eclipse, but there's probably an option somewhere to run a custom command after compilation. Or just do it yourself - let Eclipse compile, you change owner and make it setuid, then you get Eclipse to run/debug.
Your approach will work if the program is to be run stand-alone. But will it work under a debugger ? I think under a debugger program invocation mechanism is somewhat different.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to debug using Eclipse question HarryBoy Linux - Newbie 5 03-14-2014 06:59 AM
Eclipse Debug mode not working (/dev/ttys0) cyber.cbm Programming 1 09-02-2009 08:27 AM
LXer: Debug Java applications remotely with Eclipse LXer Syndicated Linux News 0 12-15-2008 04:20 PM
Debug in Eclipse as root guysoft Programming 3 10-16-2006 07:30 PM
Using Eclipse to debug from Windows To Linux flashburn Linux - Software 1 09-19-2005 06:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration