From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1698) id EFB223847830; Fri, 3 Sep 2021 18:43:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EFB223847830 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Iain D Sandoe To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-3352] coroutines: Support for debugging implementation state. X-Act-Checkin: gcc X-Git-Author: Iain Sandoe X-Git-Refname: refs/heads/master X-Git-Oldrev: a45a7ecdf34311587daa2e90cc732adcefac447b X-Git-Newrev: addf167a23f61c0ec97f6e71577a0623f3fc13e7 Message-Id: <20210903184306.EFB223847830@sourceware.org> Date: Fri, 3 Sep 2021 18:43:06 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 03 Sep 2021 18:43:07 -0000 https://gcc.gnu.org/g:addf167a23f61c0ec97f6e71577a0623f3fc13e7 commit r12-3352-gaddf167a23f61c0ec97f6e71577a0623f3fc13e7 Author: Iain Sandoe Date: Fri Jul 9 21:01:41 2021 +0100 coroutines: Support for debugging implementation state. Some of the state that is associated with the implementation is of interest to a user debugging a coroutine. In particular items such as the suspend point, promise object, and current suspend point. These variables live in the coroutine frame, but we can inject proxies for them into the outermost bind expression of the coroutine. Such variables are automatically moved into the coroutine frame (if they need to persist across a suspend expression). PLacing the proxies thus allows the user to inspect them by name in the debugger. To implement this, we ensure that (at the outermost scope) the frame entries are not mangled (coroutine frame variables are usually mangled with scope nesting information so that they do not clash). We can safely avoid doing this for the outermost scope so that we can map frame entries directly to the variables. This is partial contribution to debug support (PR 99215). Signed-off-by: Iain Sandoe gcc/cp/ChangeLog: * coroutines.cc (register_local_var_uses): Do not mangle frame entries for the outermost scope. Record the outer scope as nesting depth 0. Diff: --- gcc/cp/coroutines.cc | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index a3c780eb9f6..9ab2be04266 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -3885,8 +3885,6 @@ register_local_var_uses (tree *stmt, int *do_subtree, void *d) if (TREE_CODE (*stmt) == BIND_EXPR) { - lvd->bind_indx++; - lvd->nest_depth++; tree lvar; for (lvar = BIND_EXPR_VARS (*stmt); lvar != NULL; lvar = DECL_CHAIN (lvar)) @@ -3925,11 +3923,17 @@ register_local_var_uses (tree *stmt, int *do_subtree, void *d) continue; /* Make names depth+index unique, so that we can support nested - scopes with identically named locals. */ + scopes with identically named locals and still be able to + identify them in the coroutine frame. */ tree lvname = DECL_NAME (lvar); char *buf; - if (lvname != NULL_TREE) - buf = xasprintf ("__%s.%u.%u", IDENTIFIER_POINTER (lvname), + /* The outermost bind scope contains the artificial variables that + we inject to implement the coro state machine. We want to be able + to inspect these in debugging. */ + if (lvname != NULL_TREE && lvd->nest_depth == 0) + buf = xasprintf ("%s", IDENTIFIER_POINTER (lvname)); + else if (lvname != NULL_TREE) + buf = xasprintf ("%s_%u_%u", IDENTIFIER_POINTER (lvname), lvd->nest_depth, lvd->bind_indx); else buf = xasprintf ("_D%u.%u.%u", DECL_UID (lvar), lvd->nest_depth, @@ -3942,6 +3946,8 @@ register_local_var_uses (tree *stmt, int *do_subtree, void *d) /* We don't walk any of the local var sub-trees, they won't contain any bind exprs. */ } + lvd->bind_indx++; + lvd->nest_depth++; cp_walk_tree (&BIND_EXPR_BODY (*stmt), register_local_var_uses, d, NULL); *do_subtree = 0; /* We've done this. */ lvd->nest_depth--;