From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27740 invoked by alias); 3 Sep 2010 09:06:04 -0000 Received: (qmail 27728 invoked by uid 22791); 3 Sep 2010 09:06:02 -0000 X-SWARE-Spam-Status: No, hits=-0.4 required=5.0 tests=BAYES_05,TW_BF,TW_XB,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from isis.lip6.fr (HELO isis.lip6.fr) (132.227.60.2) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 03 Sep 2010 09:05:57 +0000 Received: from mailone.lip6.fr (mailone.desir.lip6.fr [132.227.205.6]) by isis.lip6.fr (8.14.4/lip6) with ESMTP id o8395sUt029268 for ; Fri, 3 Sep 2010 11:05:54 +0200 (CEST) X-pt: isis.lip6.fr Received: from [132.227.203.140] (myre.desir.lip6.fr [132.227.203.140]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mailone.lip6.fr (Postfix) with ESMTPSA id 911A7112 for ; Fri, 3 Sep 2010 11:05:54 +0200 (CEST) Message-ID: <4C80BA7A.3030309@lip6.fr> Date: Fri, 03 Sep 2010 09:06:00 -0000 From: Nicolas Sabouret User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.11) Gecko/20100713 Thunderbird/3.0.6 MIME-Version: 1.0 To: gdb@sourceware.org Subject: printing array in function Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit 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 X-SW-Source: 2010-09/txt/msg00007.txt.bz2 Hi all, In the frame of a 1st-year course in C (starting in next october), we are using a sub-set of gdb features (embedded in a geany plugin) to help our students understand what is going on in their code. The problem we have is that arrays passed to functions are seen as pointers by gdb. Here is a simple example : 1: void f(int tab[]) { 2: tab[0] = 1; 3: } 4: int main() { 5: int t[] = {-1,-1}; 6: f(t); 7: return 0; 8: } $ gcc -g -o test test.c $ gdb test (gdb) b 6 (gdb) run (gdb) p t -> {-1, -1} (gdb) s (gdb) p tab -> (int *) 0xbffff440 The only solution we found to display tab as an array is to use "p *tab@2", but this requires knowing the exact size of the array (2 in this example). Our problem is that the gdb calls are integrated in a front-end for students (they do not type gdb commands directly) and that our frontend has no way of "guessing" what is the correct size for the array. My question is : is there a way to display an array in a function (without knowing the size a priori). Thanks in advance for any help on this subject. -- Nicolas Sabouret, Assistant Professor University Pierre & Marie Curie http://www-poleia.lip6.fr/~sabouret