Bug 12347 - Scripted strcmp() returns incorrect, constant value
Summary: Scripted strcmp() returns incorrect, constant value
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: exp (show other bugs)
Version: unknown
: P2 normal
Target Milestone: 7.3
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-27 00:48 UTC by Josh Jore
Modified: 2011-06-02 13:17 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
repro test case (448 bytes, application/gzip)
2010-12-27 00:48 UTC, Josh Jore
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Josh Jore 2010-12-27 00:48:11 UTC
Created attachment 5165 [details]
repro test case

The glibc function strchr() is returning a constant nonsense value when used by gdb.

The original test case:

    perl -e 'system "gdb -p $$"'
    (gdb) set print pretty on
    (gdb) p $patchlevel_sv = *PL_patchlevel
    $1 = {
      sv_any = 0x9199030,
      sv_refcnt = 1,
      sv_flags = 17412,
      sv_u = {
        svu_pv = 0x919fe98 "v5.12.2",
        svu_iv = 152698520,
        svu_uv = 152698520,
        svu_rv = 0x919fe98,
        svu_array = 0x919fe98,
        svu_hash = 0x919fe98,
        svu_gp = 0x919fe98
      }
    }
    (gdb) p $patchlevel = $patchlevel_sv->sv_u.svu_pv
    $2 = 0x919fe98 "v5.12.2"
    (gdb) p strcmp($patchlevel, "v5.10")
    $3 = 3998896
    (gdb) p strcmp($patchlevel, "v5.12")
    $4 = 3998896

An automated, minimal test is attached in gdb-strcmp-repro.tar.gz:

    tar xzf gdb-strcmp-repro.tar.gz
    cd gdb-strcmp-repro
    make

The internet complaint at http://old.nabble.com/call-strcmp-tt28828726.html#a28828726 might also be an instance of this.
Comment 1 Josh Jore 2010-12-27 01:09:37 UTC
I'm using version 7.2-1ubuntu3 as provided by the Ubuntu package repository. Also fails when I build the latest CVS rev.

$ gdb -v
GNU gdb (GDB) 7.2-ubuntu
Copyright (C) 2010 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://www.gnu.org/software/gdb/bugs/>.
Comment 2 Andreas Schwab 2010-12-27 08:42:52 UTC
strcmp is the IFUNC symbol.
Comment 3 Jan Kratochvil 2011-06-02 13:17:20 UTC
This is fixed in FSF GDB HEAD and GDB 7.3-prerelease branch.
[patch 0/7] STT_GNU_IFUNC support
http://sourceware.org/ml/gdb-patches/2011-03/msg00937.html

You can download a GDB snapshot before gdb-7.3 gets released these days/weeks.
http://www.gnu.org/software/gdb/current/