From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by sourceware.org (Postfix) with ESMTPS id 06F60386187E for ; Wed, 3 Mar 2021 22:46:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 06F60386187E Received: by mail-io1-xd36.google.com with SMTP id n132so15773589iod.0 for ; Wed, 03 Mar 2021 14:46:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=J4GFBA5EzOu13tMIHqgG5OOUeSTpnXdZ1Ia5G6Eu7hU=; b=GAhEVoTPWDSNUXWkM1ajon8h4qxLG6OcLG8K8HBQwQQRYPxRhfvm9YlyCUmgD5mddR gjcjMzs6Z/YfsCLP7O3T0tb3/tYvWc7jM5++UXRkx0O/T/1C8L0UbgaqOi8eJNTpP3wU UMBoEWcA9PKedImFT7PfSIoveNQq+IqoD0/ZMvlqr/4E1LdZLx1PxQ/mcypOgl2J4Es4 0svCfjFKbMIWybUUefOp8Lh2qYSGe0E95SXfcg1ffvFEGH7L9ZdOaT87A0Q8jZCdrRWs iBZFyluytoYXM8D2JibyEGwKFzdI9WflR3XSM7D2q+Br3yRA9CM/7ZV4yND7zAl+FarX I3Jw== X-Gm-Message-State: AOAM531jPjzpa5MjRt4UPgONNhf8s4UTBBxcl/pCms6s4XwErcauO4kr sHO095sVAUkCevYAY17Dy2l+uGZzFXL17Cc383E= X-Google-Smtp-Source: ABdhPJwL8fS0g3D7eufiKLXPeX902XI9w6apOktt5gJLTpsmopISr8EIIJaeIpPDX2RvQV4H7b20PDwBenXACAHUzYY= X-Received: by 2002:a02:9003:: with SMTP id w3mr1183115jaf.31.1614811576538; Wed, 03 Mar 2021 14:46:16 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a05:6602:349:0:0:0:0 with HTTP; Wed, 3 Mar 2021 14:46:15 -0800 (PST) In-Reply-To: <56fda69d99a5bdb4e7aed891a4af0e0a6112f16e.camel@yandex.ru> References: <9f1dbafc6d1184d9ca07bdea98f696e0ca65b9e2.camel@yandex.ru> <998ef50db5faec782f174bd05394155a54830e11.camel@yandex.ru> <61f99c80b25f584bdcf0f03c271fd005a09757c4.camel@yandex.ru> <56fda69d99a5bdb4e7aed891a4af0e0a6112f16e.camel@yandex.ru> From: Peng Yu Date: Wed, 3 Mar 2021 16:46:15 -0600 Message-ID: Subject: Re: How to look up where a structure is defined? To: Konstantin Kharlamov Cc: libc-help Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-help@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-help mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Mar 2021 22:46:18 -0000 On 3/3/21, Konstantin Kharlamov wrote: > On Wed, 2021-03-03 at 16:24 -0600, Peng Yu wrote: >> On Wed, Mar 3, 2021 at 2:23 PM Konstantin Kharlamov >> wrote: >> > >> > On Wed, 2021-03-03 at 23:09 +0300, Konstantin Kharlamov wrote: >> > > On Wed, 2021-03-03 at 13:51 -0600, Peng Yu wrote: >> > > > This seems to be a complicated solution. I just want to get a >> > > > database >> > > > (a TSV file should be fine) of types and the header they appear. I >> > > > don't want to build the project just to get this info. >> > > >> > > I see, well, the Universal Ctags I mentioned should work for you. It >> > > doesn't >> > > require building the project: you just run `ctags -R` or `ctags -Re` >> > > (first >> > > for >> > > vim-style tags file, second one for emacs-style) over the repository= , >> > > and >> > > you >> > > get a `tags` or `TAGS` file with a list of definitions. >> > > >> > > Possible drawbacks on ctags I mentioned in the other email. Basicall= y >> > > it's >> > > that >> > > it doesn't take context into consideration. >> > > >> > > Regarding usage: the tags file it generates, although can be read fo= r >> > > human, >> > > supposed to be read by text editors/IDEs. Since you mention a CSV >> > > file, I >> > > assume >> > > you might want something human-readable. Please see option --output- >> > > format=3D in >> > > `man ctags` for details: I think you might want the `xref` format. (= I >> > > never >> > > tried it myself, just reading the man it seems like it what you're >> > > after). >> > >> > Although, I wouldn't hold my breath that reading a resulting xref file >> > would >> > be easy The reason being is that I expect a tags file created from >> > glibc >> > repo to be some hundreds of megabytes. For reference, a TAGS file I >> > generated long ago for libreoffice project is sized at 183M. >> > >> > So yeah, you will probably want to use the file from an IDE or text >> > editor, >> > rather than reading it manually. >> >> ctags can partially solve the problem. The declaration and definition >> of a struct are all in the header. So finding the definition is OK. >> But it can not return function declaration. Is there a way to show >> function declaration as well? (For example, ./socket/sys/socket.h for >> setsockopt().) >> >> $ grep '^icmphdr\>' tags >> icmphdr sysdeps/gnu/netinet/ip_icmp.h /^struct icmphdr$/;" s >> $ grep ^setsockopt tags >> setsockopt sysdeps/unix/sysv/linux/setsockopt.c /^setsockopt (int fd, >> int level, int optname, const void *optval, socklen_t len)$/;" f ctags only shows the above. The following is what I show where the declaration is. >> ./socket/sys/socket.h >> 215:extern int setsockopt (int __fd, int __level, int __optname, > > But, in the grep output you show you have both the declaration and the > definition of setsockopt, no? In particular, you have the declaration fro= m > `socket.h` file. > > I think you're confused because your editor/IDE navigates by default to t= he > first match in the tags file, which probably happened to be the definitio= n. > I know vim does that in particular. What to do here is depends on the > editor/IDE you're using. For vim specifically there is some command to go= to > the next tag (I think it's `:tn`). > > In Emacs it is implemented in a better way: it shows you a list of all > matches when there's more than one, and you get to chose which one you wa= nt. > Idk, perhaps there's a plugin that implements similar behavior for vim=E2= =80=A6? > Anyway, point being is that the answer depends on what you're using with = the > tags file. > > On a side note, you do need to figure it out for your editor/IDE, because= , > for example, with struct fields you might get tons of matches, depending = on > circumstances. Remember, tags does not include context. So if project has > multiple structs with a field `int foo;`, all of them will match when you= 'll > try navigate to `foo` by using tags. > > --=20 Regards, Peng