From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 116099 invoked by alias); 4 Mar 2016 16:15:32 -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 116068 invoked by uid 89); 4 Mar 2016 16:15:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1706, i1, cgit, Pretty X-HELO: mail-yw0-f175.google.com Received: from mail-yw0-f175.google.com (HELO mail-yw0-f175.google.com) (209.85.161.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 04 Mar 2016 16:15:28 +0000 Received: by mail-yw0-f175.google.com with SMTP id g127so48136056ywf.2 for ; Fri, 04 Mar 2016 08:15:28 -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:in-reply-to:references:date :message-id:subject:from:to:cc; bh=OMBKfyyZ+GhEV/8Aty4ynMtYKKAJHCO0O4AoFeMrLhg=; b=E0nbIr6gyNVqhiBvudsn3HBytMEqVI0+UYYSYQdp4qdysSkB9BccniWWECZju9jsul tXJNnXptZnE191LXaL48elLHA7I4RibKdiOpIEEs0Utn5W9oRUJHAGSnnPDe/raJAeZ9 e0SJUufGkTTDitNrd4TaXNpEHJgeAAQ7ZxfssUVnYfGA8+RCAhVma1Q4/J/abjjN2W/1 hJ2V0Q1kqssbCJ94JvTAFn7bYOLlAcBunKVDjsCaOxsNxDZmFKulsbbEDN5GYYV81Rij kfpQXZP2Fux+ge7iKQk+yBvBUCjdU+cvI2uRusoDVSF6WpB9oDzl6opiltZauNYQYB23 jnzA== X-Gm-Message-State: AD7BkJKf59nesvvEzR1CW7qR1mjNi9HiWO8I6T+OirOrDNb718J4Nrs/FHjPEtxINH+qK/l37hWwhExzALravA== MIME-Version: 1.0 X-Received: by 10.13.224.66 with SMTP id j63mr5582358ywe.301.1457108126850; Fri, 04 Mar 2016 08:15:26 -0800 (PST) Received: by 10.37.24.2 with HTTP; Fri, 4 Mar 2016 08:15:26 -0800 (PST) In-Reply-To: <20160304144231.GA7767@host1.jankratochvil.net> References: <20160304144231.GA7767@host1.jankratochvil.net> Date: Fri, 04 Mar 2016 16:15:00 -0000 Message-ID: Subject: Re: Printing a 2D array in a C program From: Neven Sajko To: Jan Kratochvil Cc: gdb@sourceware.org Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-03/txt/msg00008.txt.bz2 On 4 March 2016 at 15:42, Jan Kratochvil wrote: > On Fri, 04 Mar 2016 15:27:14 +0100, Neven Sajko wrote: >> In my C program there is a square matrix implemented as an array >> of arrays, which prints nicely in GDB with `info locals`. > > I do not understand how that can happen. > You should always provide sample code / example. > > >> But how can that nice output be accomplished if you are not in >> the function in which the array was declared, but just have it >> passed as a function parameter. > > If it is a pointer (as you say C, not C++ reference) you should be able to: > (gdb) print *thatpointername > Then GDB should IMO print it the same as a local variable is printed. > > > Printing of C++ vectors of vectors (which is BTW wrong data structure for a 2D > matrix anyway) as a matrix was implemented by Chris Moller as a Python Pretty > printer in some versions of Fedora GDB but it was later discontinued. The > initial implementation was: > http://pkgs.fedoraproject.org/cgit/rpms/gdb.git/commit/?id=6068e6305ed7d05b4a919c28aa5bcb737e1f163b > (gdb) p test2 > $2 = > { > {0 1 } > {2 3 } > {4 5 } > } > > > > Jan Thanks for your answer, Jan. In my question I asked about C (not C++), I even mentioned the gcc -std=gnu90 option. My code is thus: enum { sz = 17 }; void p(int m[sz][sz], int n) { int i; for (i=1; i