From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18985 invoked by alias); 19 Dec 2014 01:00:55 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 18971 invoked by uid 89); 19 Dec 2014 01:00:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.8 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mail-ob0-f179.google.com Received: from mail-ob0-f179.google.com (HELO mail-ob0-f179.google.com) (209.85.214.179) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 19 Dec 2014 01:00:53 +0000 Received: by mail-ob0-f179.google.com with SMTP id va2so8674159obc.10 for ; Thu, 18 Dec 2014 17:00:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=VW/4GQNGtyadgkMF6/MsRyb+vEutHsLM9Q7MZkerXDM=; b=at+/KNpHUk7Hg//lrzcAQH/J2GEknf/lDnqelx7VIFlE07OtbdKlTYWHNbZZprRCtu BT3HgluDiucHimKZhi3hIEFW8HkshKE1YkSTx2LB28+H/pu2IhM31HkFxI0abWUtHoPQ prpLtIQciXnak/P1UkKn3498Ahbkmq/bJ8iNUV2SyuWQudDk8VQuy0d3yT6w5ayYlfcT HCVg0JZLXTQIVkyC8L/mesU+op/PTKhQV8rz27fuTAPYS5MHR97yF7erir0+DGZ8PM+9 zv+aOP06+WHXJlch61JTjquDpoMKUcP4q3TOWHW8hgkCteX+Zx8GIeJnqSR/6TPfuttl Zsyg== X-Gm-Message-State: ALoCoQl193qhQFu5hIdC10gxNm8InuEtv1b2vdYoEMidSAQuzPQad2OGgVHCpGRpBHOZQd3FL+ZR MIME-Version: 1.0 X-Received: by 10.202.79.80 with SMTP id d77mr2996759oib.112.1418950851762; Thu, 18 Dec 2014 17:00:51 -0800 (PST) Received: by 10.202.225.68 with HTTP; Thu, 18 Dec 2014 17:00:51 -0800 (PST) Date: Fri, 19 Dec 2014 01:00:00 -0000 Message-ID: Subject: Getting the "description" of a variable From: Siva Chandra To: gdb Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2014-12/txt/msg00028.txt.bz2 Hello, As with most of my questions, I am really not sure if the subject line is good/apt for my question. The question is, "how can I get the description of a variable from the GDB command line?" By description, I mean this: 1. File and line it is declared at. 2. Its type and scope. I think GDB already has ways to get this information using multiple commands. My use case can be illustrated with an example. Consider the following C++ snippet. class Counter { public: int inc(); int count; }; int Counter::inc () { count++; return count; } class A { public: int inc(); static Counter counter; }; Counter A::counter; int A::inc () { counter.inc(); // Break here } int main () { A a; a.inc(); return 0; } Lets say I am new to this code and single stepping through it and currently stopped at the line marked with "Break here". I now want to know what this variable "counter" is. I print its value, and print its type. If I do "info variables counter", one of the results is "A::counter" and I realize that it is a static member of class A. Next, I can use gdb.lookup_symbol('A::counter') to get to the filename and line number where it is declared. There are a few problems I face when I use this kind of workflow: 1. Too many steps to get to what I want. If I am interrupted, I loose track of where I am and will have to start from the beginning all over. 2. gdb.lookup_symbol('counter') returns (None, True). I have to use gdb.lookup_symbol('A::counter'). 3. The filename and line number I get via gdb.lookup_symbol is mostly likely the location where the static member is declared out of the class in a *.cc file. This is not good enough because the comments describing this member are typically found in a *.h file where the class is defined. So, I will need another step via gdb.lookup_symbol('A') to get to the line and file where the class A is defined. Is there a shorter workflow to get the same information already existing in GDB? If not: 1. Is it OK to add more info to 'struct symbol' to store all the files and lines where a "symbol" is declared. If not 'struct symbol', is there a better place where such info can be added? 2. If #1 is OK, then, can we add a command 'describe' using GDB Python which prints the info I am looking for? Thanks, Siva Chandra