From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7833) id 62FEB3857704; Wed, 3 May 2023 16:24:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62FEB3857704 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683131069; bh=A+wyHp5JGAGael1cpGpUJbvvk4WBIkBR38LET4CAMxc=; h=From:To:Subject:Date:From; b=XGdamUg3KVwEyNNEXL7hBP2oThP3R1GWVEpBz6Df0PXytApDKF3av1mQ18ZvplifQ vIYRSeuG4rSYO98Ej1gkoYzbF/0kHxpp2B4pMK2cjGIwxUhj098BH++MY7RYuPG3LH 419eAjiJpdapS3KKM+Af0ASJFXJeQX8VwdJ6ekIU= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Lancelot SIX To: gdb-cvs@sourceware.org Subject: [binutils-gdb/lsix/poke-gdb] gdb/poke: Various style updates and fixes X-Act-Checkin: binutils-gdb X-Git-Author: Lancelot SIX X-Git-Refname: refs/heads/lsix/poke-gdb X-Git-Oldrev: b0c1ee05b1e3cb00b19766f1c0e161486498442c X-Git-Newrev: 9d13358a1331c2da7c3ef97d8be3da7c1ce519fc Message-Id: <20230503162429.62FEB3857704@sourceware.org> Date: Wed, 3 May 2023 16:24:29 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D9d13358a1331= c2da7c3ef97d8be3da7c1ce519fc commit 9d13358a1331c2da7c3ef97d8be3da7c1ce519fc Author: Lancelot SIX Date: Tue Sep 20 14:36:55 2022 +0100 gdb/poke: Various style updates and fixes =20 This patch mostly contains changes which would have been comments in a normal review. Diff: --- gdb/doc/poke.texi | 8 ++++---- gdb/poke.c | 51 +++++++++++++++++++++++++++------------------------ 2 files changed, 31 insertions(+), 28 deletions(-) diff --git a/gdb/doc/poke.texi b/gdb/doc/poke.texi index b6c62857d43..c7a3a8b43a4 100644 --- a/gdb/doc/poke.texi +++ b/gdb/doc/poke.texi @@ -66,8 +66,8 @@ result: This declares a couple of Poke types and a variable: =20 @smallexample -(@value{GDBP}) type byte =3D uint<8> -(@value{GDBP}) type Packet =3D struct @{ byte magic =3D=3D 0x4a; byte sz; \ +(@value{GDBP}) poke type byte =3D uint<8> +(@value{GDBP}) poke type Packet =3D struct @{ byte magic =3D=3D 0x4a; byte= sz; \ byte[sz] payload; @} (@value{GDBP}) poke Packet @{ sz =3D 4 @} Packet @{ @@ -75,7 +75,7 @@ Packet @{ sz=3D0x4UB, payload=3D[0x0UB,0x0UB,0x0UB,0x0UB] @} -(@value{GDBP}) var p =3D Packet @{ sz =3D 4 @} +(@value{GDBP}) poke var p =3D Packet @{ sz =3D 4 @} (@value{GDBP}) poke p.payload [0x0UB,0x0UB,0x0UB,0x0UB] @end smallexample @@ -339,7 +339,7 @@ short counter; In @value{GDBN} we can access to the value of that variable like this: =20 @smallexample -(@value{GDBN}) counter +(@value{GDBN}) p counter $1 =3D 0 @end smallexample =20 diff --git a/gdb/poke.c b/gdb/poke.c index 7bd3bfe4711..a2adb0e2246 100644 --- a/gdb/poke.c +++ b/gdb/poke.c @@ -190,11 +190,11 @@ iod_get_if_name (void) static char * iod_handler_normalize (const char *handler, uint64_t flags, int *error) { - char *new_handler =3D NULL; + char *new_handler =3D nullptr; =20 if (strcmp (handler, "") =3D=3D 0) new_handler =3D xstrdup (handler); - if (error) + if (error !=3D nullptr) *error =3D PK_IOD_OK; =20 return new_handler; @@ -356,7 +356,7 @@ poke_alien_token_handler (const char *id, char **errmsg) goto error; } =20 - *errmsg =3D NULL; + *errmsg =3D nullptr; return &alien_token; =20 error: @@ -364,13 +364,13 @@ poke_alien_token_handler (const char *id, char **errm= sg) emsg +=3D id; emsg +=3D "'"; *errmsg =3D xstrdup (emsg.c_str ()); - return NULL; + return nullptr; } =20 /* Given a string, prefix it in order to avoid collision with Poke's keywords. */ =20 -static std::vector poke_keywords +static const std::vector poke_keywords { "pinned", "struct", "union", "else", "while", "until", "for", "in", "where", "if", "sizeof", "fun", "method", @@ -394,7 +394,7 @@ normalize_poke_identifier (std::string prefix, std::str= ing str) /* Given a GDB type name, mangle it to a valid Poke type name. */ =20 static std::string -gdb_type_name_to_poke (std::string str, struct type *type =3D NULL) +gdb_type_name_to_poke (std::string str, struct type *type =3D nullptr) { for (int i =3D 0; i < str.length (); ++i) if (!(str.begin()[i] =3D=3D '_' @@ -429,7 +429,7 @@ poke_add_type (struct type *type) =20 if (type !=3D nullptr) { - if (type->name ()) + if (type->name () !=3D nullptr) type_name =3D type->name (); =20 /* Do not try to add a type that is already defined. */ @@ -450,13 +450,13 @@ poke_add_type (struct type *type) } case TYPE_CODE_TYPEDEF: { - struct type *target_type =3D TYPE_TARGET_TYPE (type); + struct type *target_type =3D check_typedef (type); std::string target_type_code =3D poke_add_type (target_type); =20 if (target_type_code =3D=3D "") goto skip; =20 - if (target_type->name ()) + if (target_type->name () !=3D nullptr) str +=3D gdb_type_name_to_poke (target_type->name (), target_type); else str +=3D target_type_code; @@ -504,17 +504,20 @@ poke_add_type (struct type *type) for (int idx =3D 0; idx < type->num_fields (); idx++) { std::string field_name - =3D normalize_poke_identifier ("__f", type->field (idx).name ()); - struct type *field_type =3D type->field (idx).type (); + =3D normalize_poke_identifier ("__f", + type->field (idx).name ()); + struct type *field_type + =3D check_typedef (type->field (idx).type ()); size_t field_bitpos =3D type->field (idx).loc_bitpos (); =20 if (idx > 0) str +=3D " "; - if (field_type->name ()) + if (field_type->name () !=3D nullptr) { if (poke_add_type (field_type) =3D=3D "") goto skip; - str +=3D gdb_type_name_to_poke (field_type->name (), field_type); + str +=3D gdb_type_name_to_poke (field_type->name (), + field_type); } else { @@ -594,7 +597,7 @@ poke_handle_exception (pk_val exception) =20 if (handler =3D=3D PK_NULL) error (_("Couldn't get a handler for poke gdb_exception_handler")); - if (pk_call (poke_compiler, handler, NULL, NULL, 1, exception) + if (pk_call (poke_compiler, handler, nullptr, nullptr, 1, exception) =3D=3D PK_ERROR) error (_("Couldn't call gdb_exception_handler in poke")); } @@ -611,7 +614,7 @@ start_poke (void) types. */ poke_compiler =3D pk_compiler_new_with_flags (&poke_term_if, PK_F_NOSTDTYPES); - if (poke_compiler =3D=3D NULL) + if (poke_compiler =3D=3D nullptr) error (_("Couldn't start the poke incremental compiler.")); poke_compiler_lives =3D true; =20 @@ -628,7 +631,7 @@ start_poke (void) /* Define a handler that we will use for processing unhandled Poke exceptions. */ if (pk_compile_buffer (poke_compiler, poke_exception_handler, - NULL, &exit_exception) !=3D PK_OK + nullptr, &exit_exception) !=3D PK_OK || exit_exception !=3D PK_NULL) error (_("Could not define the Poke default exception handler")); =20 @@ -637,7 +640,7 @@ start_poke (void) if (pk_register_iod (poke_compiler, &iod_if) !=3D PK_OK) error (_("Could not register the foreign IO device interface in poke."= )); =20 - if (pk_compile_buffer (poke_compiler, "open (\"\");", NULL, + if (pk_compile_buffer (poke_compiler, "open (\"\");", nullptr, &exit_exception) !=3D PK_OK || exit_exception !=3D PK_NULL) { @@ -665,7 +668,7 @@ poke_finalize (void *arg) pk_val val, exit_exception; if (pk_compile_statement (poke_compiler, "try close (get_ios); catch if E_no_ios {}", - NULL, &val, &exit_exception) !=3D PK_OK + nullptr, &val, &exit_exception) !=3D PK_OK || exit_exception !=3D PK_NULL) error (_("Error while closing an IOS on exit.")); =20 @@ -743,14 +746,14 @@ poke_command (const char *args, int from_tty) && ((input)[sizeof (cmd) - 1] =3D=3D ' ' || (input)[sizeof (cmd) - 1] = =3D=3D '\t')) =20 args =3D skip_spaces (args); - if (args =3D=3D NULL) + if (args =3D=3D nullptr) return; =20 if (IS_COMMAND (args, "fun")) - { - what =3D 0; - cmd =3D args; - } + { + what =3D 0; + cmd =3D args; + } else { if (IS_COMMAND (args, "var") @@ -820,5 +823,5 @@ Usage: poke-dump-types\n")); Execute a Poke statement or declaration.\n\ Usage: poke [STMT]\n")); =20 - make_final_cleanup (poke_finalize, NULL); + make_final_cleanup (poke_finalize, nullptr); }