btf: print string position as comment for validation and testing purposes.

Message ID 20240108105552.714778-1-cupertino.miranda@oracle.com
State Accepted
Headers
Series btf: print string position as comment for validation and testing purposes. |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Cupertino Miranda Jan. 8, 2024, 10:55 a.m. UTC
  Hi everyone,

This patch adds a comment to the BTF strings regarding their position
within the section. This is useful for assembly inspection purposes.

Regards,
Cupertino

When using -dA, this function was only printing as comment btf_string or
btf_aux_string.
This patch changes the comment to also include the position of the
string within the section in hexadecimal format.

gcc/ChangeLog:
	* btfout.cc (output_btf_strs): Changed.
---
 gcc/btfout.cc | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Comments

David Faust Jan. 8, 2024, 5:07 p.m. UTC | #1
Hi Cupertino,

On 1/8/24 02:55, Cupertino Miranda wrote:
> Hi everyone,
> 
> This patch adds a comment to the BTF strings regarding their position
> within the section. This is useful for assembly inspection purposes.
> 
> Regards,
> Cupertino
> 
> When using -dA, this function was only printing as comment btf_string or
> btf_aux_string.
> This patch changes the comment to also include the position of the
> string within the section in hexadecimal format.
> 
> gcc/ChangeLog:
> 	* btfout.cc (output_btf_strs): Changed.

Please be a little bit more expressive in the ChangeLog.
Something along the lines of "print string offset in comment" will be
much more useful.

LGTM with that change, please apply.
Thanks!

> ---
>  gcc/btfout.cc | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/gcc/btfout.cc b/gcc/btfout.cc
> index db4f1084f85c..04218adc9e66 100644
> --- a/gcc/btfout.cc
> +++ b/gcc/btfout.cc
> @@ -1081,17 +1081,20 @@ static void
>  output_btf_strs (ctf_container_ref ctfc)
>  {
>    ctf_string_t * ctf_string = ctfc->ctfc_strtable.ctstab_head;
> +  static int str_pos = 0;
>  
>    while (ctf_string)
>      {
> -      dw2_asm_output_nstring (ctf_string->cts_str, -1, "btf_string");
> +      dw2_asm_output_nstring (ctf_string->cts_str, -1, "btf_string, str_pos = 0x%x", str_pos);
> +      str_pos += strlen(ctf_string->cts_str) + 1;
>        ctf_string = ctf_string->cts_next;
>      }
>  
>    ctf_string = ctfc->ctfc_aux_strtable.ctstab_head;
>    while (ctf_string)
>      {
> -      dw2_asm_output_nstring (ctf_string->cts_str, -1, "btf_aux_string");
> +      dw2_asm_output_nstring (ctf_string->cts_str, -1, "btf_aux_string, str_pos = 0x%x", str_pos);
> +      str_pos += strlen(ctf_string->cts_str) + 1;
>        ctf_string = ctf_string->cts_next;
>      }
>  }
  
Cupertino Miranda Jan. 8, 2024, 6:37 p.m. UTC | #2
Thanks! Committed.

David Faust writes:

> Hi Cupertino,
>
> On 1/8/24 02:55, Cupertino Miranda wrote:
>> Hi everyone,
>>
>> This patch adds a comment to the BTF strings regarding their position
>> within the section. This is useful for assembly inspection purposes.
>>
>> Regards,
>> Cupertino
>>
>> When using -dA, this function was only printing as comment btf_string or
>> btf_aux_string.
>> This patch changes the comment to also include the position of the
>> string within the section in hexadecimal format.
>>
>> gcc/ChangeLog:
>> 	* btfout.cc (output_btf_strs): Changed.
>
> Please be a little bit more expressive in the ChangeLog.
> Something along the lines of "print string offset in comment" will be
> much more useful.
>
> LGTM with that change, please apply.
> Thanks!
>
>> ---
>>  gcc/btfout.cc | 7 +++++--
>>  1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/gcc/btfout.cc b/gcc/btfout.cc
>> index db4f1084f85c..04218adc9e66 100644
>> --- a/gcc/btfout.cc
>> +++ b/gcc/btfout.cc
>> @@ -1081,17 +1081,20 @@ static void
>>  output_btf_strs (ctf_container_ref ctfc)
>>  {
>>    ctf_string_t * ctf_string = ctfc->ctfc_strtable.ctstab_head;
>> +  static int str_pos = 0;
>>
>>    while (ctf_string)
>>      {
>> -      dw2_asm_output_nstring (ctf_string->cts_str, -1, "btf_string");
>> +      dw2_asm_output_nstring (ctf_string->cts_str, -1, "btf_string, str_pos = 0x%x", str_pos);
>> +      str_pos += strlen(ctf_string->cts_str) + 1;
>>        ctf_string = ctf_string->cts_next;
>>      }
>>
>>    ctf_string = ctfc->ctfc_aux_strtable.ctstab_head;
>>    while (ctf_string)
>>      {
>> -      dw2_asm_output_nstring (ctf_string->cts_str, -1, "btf_aux_string");
>> +      dw2_asm_output_nstring (ctf_string->cts_str, -1, "btf_aux_string, str_pos = 0x%x", str_pos);
>> +      str_pos += strlen(ctf_string->cts_str) + 1;
>>        ctf_string = ctf_string->cts_next;
>>      }
>>  }
  

Patch

diff --git a/gcc/btfout.cc b/gcc/btfout.cc
index db4f1084f85c..04218adc9e66 100644
--- a/gcc/btfout.cc
+++ b/gcc/btfout.cc
@@ -1081,17 +1081,20 @@  static void
 output_btf_strs (ctf_container_ref ctfc)
 {
   ctf_string_t * ctf_string = ctfc->ctfc_strtable.ctstab_head;
+  static int str_pos = 0;
 
   while (ctf_string)
     {
-      dw2_asm_output_nstring (ctf_string->cts_str, -1, "btf_string");
+      dw2_asm_output_nstring (ctf_string->cts_str, -1, "btf_string, str_pos = 0x%x", str_pos);
+      str_pos += strlen(ctf_string->cts_str) + 1;
       ctf_string = ctf_string->cts_next;
     }
 
   ctf_string = ctfc->ctfc_aux_strtable.ctstab_head;
   while (ctf_string)
     {
-      dw2_asm_output_nstring (ctf_string->cts_str, -1, "btf_aux_string");
+      dw2_asm_output_nstring (ctf_string->cts_str, -1, "btf_aux_string, str_pos = 0x%x", str_pos);
+      str_pos += strlen(ctf_string->cts_str) + 1;
       ctf_string = ctf_string->cts_next;
     }
 }