From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8914 invoked by alias); 18 May 2011 15:28:09 -0000 Received: (qmail 8905 invoked by uid 22791); 18 May 2011 15:28:09 -0000 X-SWARE-Spam-Status: No, hits=-6.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_BJ,TW_CP,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 18 May 2011 15:27:50 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p4IFRn1l008710 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 18 May 2011 11:27:50 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p4IF0Imj025752; Wed, 18 May 2011 11:00:18 -0400 Received: from opsy.redhat.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id p4IF0Hik022599; Wed, 18 May 2011 11:00:18 -0400 Received: by opsy.redhat.com (Postfix, from userid 500) id 8071D508613; Wed, 18 May 2011 09:00:17 -0600 (MDT) From: Tom Tromey To: dje@google.com (Doug Evans) Cc: gdb-patches@sourceware.org Subject: Re: [RFA] Add support for $sdir and $pdir to libthread-db-search-path References: <20110510190926.A294F246199@ruffy.mtv.corp.google.com> Date: Wed, 18 May 2011 15:28:00 -0000 In-Reply-To: (Tom Tromey's message of "Thu, 12 May 2011 14:12:07 -0600") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-05/txt/msg00398.txt.bz2 Tom> Well, actually, I think the pre-existing code has some problems, but Tom> they aren't introduced by your patch. I will clean them up separately. I am checking this in on the trunk. This removes PATH_MAX from linux-thread-db.c. It also fixes the check for an absolute file name, which was incorrect in the earlier code. Built and regtested by the buildbot. Tom 2011-05-18 Tom Tromey * linux-thread-db.c (try_thread_db_load_from_pdir_1): Fix absolute path check. Use xmalloc and cleanups. (try_thread_db_load_from_dir): Use xmalloc and cleanups. diff --git a/gdb/linux-thread-db.c b/gdb/linux-thread-db.c index 179986f..f43efc7 100644 --- a/gdb/linux-thread-db.c +++ b/gdb/linux-thread-db.c @@ -819,29 +819,29 @@ try_thread_db_load (const char *library) static int try_thread_db_load_from_pdir_1 (struct objfile *obj) { - char path[PATH_MAX], *cp; + struct cleanup *cleanup; + char *path, *cp; + int result; - gdb_assert (strlen (obj->name) < sizeof (path)); - strcpy (path, obj->name); - cp = strrchr (path, '/'); - - if (cp == NULL) + if (obj->name[0] != '/') { warning (_("Expected absolute pathname for libpthread in the" - " inferior, but got %s."), path); - return 0; - } - else if (cp + 1 + strlen (LIBTHREAD_DB_SO) + 1 > path + sizeof (path)) - { - warning (_("Unexpected: path to libpthread in the inferior is" - " too long: %s"), path); + " inferior, but got %s."), obj->name); return 0; } - else - { - strcpy (cp + 1, LIBTHREAD_DB_SO); - return try_thread_db_load (path); - } + + path = xmalloc (strlen (obj->name) + 1 + strlen (LIBTHREAD_DB_SO) + 1); + cleanup = make_cleanup (xfree, path); + + strcpy (path, obj->name); + cp = strrchr (path, '/'); + /* This should at minimum hit the first character. */ + gdb_assert (cp != NULL); + strcpy (cp + 1, LIBTHREAD_DB_SO); + result = try_thread_db_load (path); + + do_cleanups (cleanup); + return result; } /* Handle $pdir in libthread-db-search-path. @@ -888,24 +888,20 @@ try_thread_db_load_from_sdir (void) static int try_thread_db_load_from_dir (const char *dir, size_t dir_len) { - char path[PATH_MAX]; + struct cleanup *cleanup; + char *path; + int result; - if (dir_len + 1 + strlen (LIBTHREAD_DB_SO) + 1 > sizeof (path)) - { - char *cp = xmalloc (dir_len + 1); - - memcpy (cp, dir, dir_len); - cp[dir_len] = '\0'; - warning (_("libthread-db-search-path component too long," - " ignored: %s."), cp); - xfree (cp); - return 0; - } + path = xmalloc (dir_len + 1 + strlen (LIBTHREAD_DB_SO) + 1); + cleanup = make_cleanup (xfree, path); memcpy (path, dir, dir_len); path[dir_len] = '/'; strcpy (path + dir_len + 1, LIBTHREAD_DB_SO); - return try_thread_db_load (path); + result = try_thread_db_load (path); + + do_cleanups (cleanup); + return result; } /* Search libthread_db_search_path for libthread_db which "agrees"