LinuxQuestions.org
Visit the LQ Articles and Editorials section
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
 
LinkBack Search this Thread
Old 07-10-2010, 09:54 PM   #1
xoran99
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Rep: Reputation: 1
Question gdb (and gmp)


I've been writing a lot of code that uses The GNU Multiple Precision Arithmetic Library, and I would like to be able to use gdb on these programs. The issue is being able to print the values of gmp variables. The documentation suggests using this .gdbinit, but if I try I tend to get segfaults.

So, I have two questions.
  1. How would I use the .gdbinit file to print the value of a gmp variable?
  2. I could try to call gmp_printf (which is in the gmp library) to print out the values, but these functions are unavailable to me (no symbol "gmp_printf" in the current context). How would I use these functions?

Thanks in advance.
 
Old 07-11-2010, 03:40 PM   #2
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,858
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

1. .gdbinit is provided as an add-on precisely to ALLOW you to print GMP variables from GDB. You're apparently already using it (that's why you're getting the segfaults). *Why* you're getting the segfaults - I couldn't even begin to speculate without looking at a stack trace and debugging the code (your application, GMP, and everything in between).

2. An alternative to using .ginit is to simply recompile GMP and make sure your GDB search path includes a) all your own code (compiled with "-g" or equivalent), and b) all the GMP code (also compiled with "-g" or equivalent). One problem with this approach, as mentioned in the documentation you cited, is that GMP has a number of symbols with the SAME NAME, but in PARALLEL directories. Which can be messy to deal with...

3. A third approach - one which NEEDN'T require gdb and/or .gdbinit - is to use the GMP call "gmp_printf()". You simply add this to your application code - just as you would add "printf()".

If you haven't already done so, I would strongly encourage you to join a GMP mail list and seek advice there, too:

http://gmplib.org/mailman/listinfo

'Hope that helps .. PSM
 
1 members found this post helpful.
Old 07-11-2010, 04:05 PM   #3
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
Originally Posted by xoran99 View Post
I've been writing a lot of code that uses The GNU Multiple Precision Arithmetic Library, and I would like to be able to use gdb on these programs. The issue is being able to print the values of gmp variables. The documentation suggests using this .gdbinit, but if I try I tend to get segfaults.

So, I have two questions.
  1. How would I use the .gdbinit file to print the value of a gmp variable?
  2. I could try to call gmp_printf (which is in the gmp library) to print out the values, but these functions are unavailable to me (no symbol "gmp_printf" in the current context). How would I use these functions?

Thanks in advance.
Well, first I read Paul's answer - I am not sure what segfaults occur - in the program or in 'gdb' itself - I'm afraid the latter, but I am not sure.

A couple of thoughts not directly addressing your problem:

1) if your 'gdb' is not the newest (7.1) and it crashes, build the newest one from source - I've just done it using

Code:
./configure CC=/mnt/sdb8/sergei/AFSWD_debug/install/gcc-4.4.4/binsh/gcc CFLAGS=-I/mnt/sdb8/sergei/AFSWD_debug/install/ncurses-5.7/include LDFLAGS=-L/mnt/sdb8/sergei/AFSWD_debug/install/ncurses-5.7/lib
make
commands - 'gdb' needs 'ncurses' (even though the documentation doesn't mention it), so you'll need development headers. Hopefully your stock gcc + ncurses will be good enough.

2) gmp-5.0.0 might be "odd", even though I didn't look inside. I mean that gmp-5.0.1 + mpfr-3.0.0 used to build gcc-4.4.4, which are all then used to build sbcl-1.0.39, cause build failure of the latter.

OTOH, gmp-4.3.2 + mpfr-2.4.2 used to build gcc-4.4.4, which are all then used to build sbcl-1.0.39, produce normal build.

I didn't dig deeper.

Last edited by Sergei Steshenko; 07-11-2010 at 05:18 PM.
 
1 members found this post helpful.
Old 07-11-2010, 09:36 PM   #4
xoran99
LQ Newbie
 
Registered: Jan 2009
Posts: 3

Original Poster
Rep: Reputation: 1
I figured out what's wrong. It turns out that the .gdbinit file provided is not exactly correct; one cannot apply __gmpz_dump to $->_mp_num (or $->_mp_den); one must apply it to its ADDRESS for __gmpz_dump to get what it's expecting. D'oh.

I will join the mailing list for future concerns. Thanks to both of you for your comments.
 
1 members found this post helpful.
Old 07-11-2010, 10:19 PM   #5
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,858
Blog Entries: 1

Rep: Reputation: Disabled
Cool - glad you got it working!

And thank you for sharing HOW you got it working!

Sincerely .. PSM
 
  


Reply

Tags
gdb


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing gmp cybernike Linux - Newbie 1 05-15-2008 02:41 PM
normal gdb and spec gdb for kgdb Igor007 Programming 1 09-23-2005 04:15 PM
normal gdb and spec gdb for kgdb Igor007 Linux - Newbie 1 09-23-2005 01:41 PM
gdb .. looking for 32 bit gdb.. for ia64 suse.. nkshirsagar Suse/Novell 0 12-09-2004 03:02 AM
trying to use gmp BadTaste Programming 1 08-04-2004 09:10 AM


All times are GMT -5. The time now is 04:36 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration