From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id wPAkKjzsY2C/fAAAWB0awg (envelope-from ) for ; Tue, 30 Mar 2021 23:27:56 -0400 Received: by simark.ca (Postfix, from userid 112) id AAA681EE0E; Tue, 30 Mar 2021 23:27:56 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-1.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id B83561E783 for ; Tue, 30 Mar 2021 23:27:55 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 762EC3857C4C; Wed, 31 Mar 2021 03:27:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 762EC3857C4C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1617161275; bh=6oDJr94cKozgtdyMkv1DBOk5IWFopMW2BkaIgHOZxA0=; h=References:In-Reply-To:Date:Subject:To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=benbQhtItB5auI3n7gLKPSMFLYYzzk6qHmbFQY5DCKe3uKtbCAi+cl+hORCtmwn3O nBNrxNOpyLno+2JJtjmzf5NaTAdmOsjwx7U0ZrkIdYXmKrtD19+jq1jn3y3FCJCDlt 5u5wo7wFol+BGMD+bNeJEmBWOU4VXZuPOAurV81A= Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id 9B1C03857C4C for ; Wed, 31 Mar 2021 03:27:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9B1C03857C4C Received: by mail-pj1-x1036.google.com with SMTP id q6-20020a17090a4306b02900c42a012202so500232pjg.5 for ; Tue, 30 Mar 2021 20:27:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=6oDJr94cKozgtdyMkv1DBOk5IWFopMW2BkaIgHOZxA0=; b=R1e3fX7g7v6e3+ZOCrjsjoT4IuTakeSJKtaLwMT6yaqK5Iz4rUHBcKya9sfEvQ5wkF G0qNAB+J6QJDeOoQxQ2tRwPZTCcJvr7j34T9u77/16EFnrCKzVAMxtGosP6WFkN+OdDV E6mKujXzzMX8p3vXQQgUHaVuuJD9L6ke2T7dYWgknJO4DNgo8C0EaExzdk6DgBoODltE s1Z2edkTcCvW/uC1xAetIf+n5eoB5DjFlfjJeRpzVeB8Nv1NBzeZ1f19F5SFqjhbd8KL x4Ju+JSzTxx/mmhcAhkE1ePUxZUNZKzGFRs7qqUeFnXv0pwm+V4yBk+SDHPe/3GrWZFR fdcA== X-Gm-Message-State: AOAM531p6reUKfPTkmlMoEUIuPejJGyNp1A/OOAiCXFAqwh9DyzD5PqV IzTNapoDiK0orPrGzdGqvI4rM+Ag2gXxB9rqAos= X-Google-Smtp-Source: ABdhPJy5jVKGGwYyzj8QzFMOUYy998gxpkBlwU0y9lFCdjaI5YMvQfUf+5Llx0tfW+JjwTCl+o1zJ3OoYma2ia90aCc= X-Received: by 2002:a17:902:dac2:b029:e6:30a6:4c06 with SMTP id q2-20020a170902dac2b02900e630a64c06mr1275400plx.65.1617161271736; Tue, 30 Mar 2021 20:27:51 -0700 (PDT) MIME-Version: 1.0 References: <6b00bbbe-1400-7f11-bdcf-811595bf8e31@polymtl.ca> <1c8fec3c-0d7e-d133-bf88-adaf764473f1@polymtl.ca> In-Reply-To: <1c8fec3c-0d7e-d133-bf88-adaf764473f1@polymtl.ca> Date: Tue, 30 Mar 2021 20:27:40 -0700 Message-ID: Subject: Re: Remote query for structure layout To: Simon Marchi Content-Type: text/plain; charset="UTF-8" X-BeenThere: gdb@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: David Blaikie via Gdb Reply-To: David Blaikie Cc: Tim Newsome , gdb Errors-To: gdb-bounces@sourceware.org Sender: "Gdb" (let me know if I'm just being an unhelpful bystander here - I clearly don't have a lot of context) On Tue, Mar 30, 2021 at 5:16 PM Simon Marchi wrote: > > On 2021-03-30 6:44 p.m., David Blaikie wrote: > > If it's "just" some user-code, is there a variable of the desired type being declared around the function call? > > AFAIK, this type wouldn't be used by the FreeRTOS code at all, so no. > Again, here's my understanding, hopefully it's close enough to the > reality. > > When a trap occurs, FreeRTOS saves the current task's register values on > the task's stack, using some arch-specific assembly code. For example, > for RISC-V: > > https://github.com/FreeRTOS/FreeRTOS-Kernel/blob/534eba66ce4a5bda45d5edeeb81ac5a3cf6d0df8/portable/GCC/RISC-V/portASM.S#L121 Ah, OK. So this is part of signal handling - so it's not part of the code that's compiled into the user's program, for instance... not even in some system library linked in, necessarily, I guess? > The way these registers are pushed is an implementation detail of > FreeRTOS. And we can imagine that it can vary depending on the > compile-time FreeRTOS configuration, I guess in the worst case it could be totally dynamic - it could pick a different layout each time. (guess a side question: How's this different from other systems? I don't know how other/more common systems handle registers during signals) > which OpenOCD doesn't know about. > > To get register values of scheduled out tasks, OpenOCD needs to > interpret these register values from the tasks' stacks. > > So Tim's suggestion is: have FreeRTOS declare a structure that has the > exact layout as the saved registers on the stack: > > struct freertos_saved_regs { > int x1; > int x5; > int x6; > ... > }; > > Consumers could read that structure's layout from the DWARF info, and > read the register values based on that. That would be a lot more robust > than hard-coding in the consumers how FreeRTOS stores things. If practical experience has shown the hard-coding is not stable/reliable (than FreeRTOS does change its strategy from time to time - but it's always constant for any given build of the FreeRTOS) I guess. But I'm not sure where FreeRTOS would expose this structure to user code - it's not like there's a system library header that user code must include... > However, since that struct would never actually be used by FreeRTOS' > code, the compiler won't emit it. Hence the need to find a way to force > the compiler to include it in the DWARF. > > Does that clarify the situation? Somewhat - any lack of understanding is just my ignorance in this field/area in general, to be clear. (I'm also not a core gdb developer, so I'm not the sort of person you have to convince of anything - just a curious bystander trying to understand/maybe offer some insightful suggestions (I predominantly work on LLVM's debug info emission, so that's my background/connection)) - Dave