diff mbox

[v4] gdb/hppa-tdep.c: Fix logical working flow issues and check additional store instructions

Message ID 548D93E4.2000405@gmail.com
State New
Headers show

Commit Message

Chen Gang Dec. 14, 2014, 1:43 p.m. UTC
Original working flow has several issues:

 - typo issue: "(inst >> 26) == 0x1f && ..." for checking 'stw(m)'.

 - compiler warning: "(inst >> 6) & 0xf) == 0x9" for checking 'sth'.

 - "(inst >> 6) == 0xa" needs to be "((inst >> 6) & 0xf) == 0xa".

And also need check additional store instructions:

 - For absolute memory: 'stby', 'stdby'.

 - For unaligned: 'stwa', 'stda'.

The original code also can be improved:

 - Remove redundant double check "(inst >> 26) == 0x1b" for 'stwm'.

 - Use 2 'switch' statements instead of all 'if' statements.

2014-12-14  Chen Gang  <gang.chen.5i5j@gmail.com>

	* hppa-tdep.c (inst_saves_gr): Fix logical working flow issues
	and check additional store instructions.
---
 gdb/hppa-tdep.c | 111 +++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 85 insertions(+), 26 deletions(-)

Comments

Joel Brobecker Dec. 14, 2014, 7:35 p.m. UTC | #1
> 2014-12-14  Chen Gang  <gang.chen.5i5j@gmail.com>
> 
> 	* hppa-tdep.c (inst_saves_gr): Fix logical working flow issues
> 	and check additional store instructions.

Review full disclosure: This is only a spot-check review, since
I no longer have much clue nor interest in hppa. I normally find
that it's fine to just trust the submitter, but then usually
the submitter has a way to actually test the patch, which is not
your case IIUC. Regardless, I will trust you that your patch does
the right thing (tm)...

> ---
>  gdb/hppa-tdep.c | 111 +++++++++++++++++++++++++++++++++++++++++++-------------
>  1 file changed, 85 insertions(+), 26 deletions(-)
> 
> diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
> index 627f31a..4f52e43 100644
> --- a/gdb/hppa-tdep.c
> +++ b/gdb/hppa-tdep.c
> @@ -1376,37 +1376,96 @@ is_branch (unsigned long inst)
>  }
>  
>  /* Return the register number for a GR which is saved by INST or
> -   zero it INST does not save a GR.  */
> +   zero it INST does not save a GR.

While changing this, can you change "zero it" -> "zero if".

> +     Store a word or doubleword using an absolute memory address formed
> +     using short or long displace- ment or indexed
                            ^^^^^^^^^^^^^^

"displace- ment" -> "displacement".

> +static int
> +inst_saves_gr (unsigned long inst)
> +{
> +  switch ((inst >> 26) & 0x0f)
> +    {
> +      case 0x03:
> +	switch ((inst >> 6) & 0x0f)
> +	  {
> +	    case 0x08:
> +	    case 0x09:
> +	    case 0x0a:
> +	    case 0x0b:
> +	    case 0x0c:
> +	    case 0x0d:
> +	    case 0x0e:
> +	    case 0x0f:
> +	      break;
> +	    default:
> +	      return 0;
> +	  }
> +	/* Fall through */
> +      case 0x18:
> +      case 0x19:
> +      case 0x1a:
> +      case 0x1b:
> +      case 0x1c:
> +      /* no 0x1d or 0x1e -- according to parisc 2.0 document */
> +      case 0x1f:
> +	return hppa_extract_5R_store (inst);
> +      default:
> +	return 0;

Quite honestly, I find your code quite confusing because of
the fall-through. It's up to you, but wouldn't it be clearer
if you had "hppa_extract_5R_store (inst)" instead of "break" +
the "/* Fall through */" ?
Chen Gang Dec. 15, 2014, 4:38 a.m. UTC | #2
On 12/15/14 03:35, Joel Brobecker wrote:
>> 2014-12-14  Chen Gang  <gang.chen.5i5j@gmail.com>
>>
>> 	* hppa-tdep.c (inst_saves_gr): Fix logical working flow issues
>> 	and check additional store instructions.
> 
> Review full disclosure: This is only a spot-check review, since
> I no longer have much clue nor interest in hppa. I normally find
> that it's fine to just trust the submitter, but then usually
> the submitter has a way to actually test the patch, which is not
> your case IIUC. Regardless, I will trust you that your patch does
> the right thing (tm)...
> 

Excuse me, I have no related test environments for parisc either. Maybe
I can try to construct the related virtual environments for it, but I am
still not quite sure whether it is enough.

Can we change to another way for it:

 - try to keep the original code no touch.

 - only fix the related typo issues according to the related documents,
   do not add new features (e.g. do not check stby, stbdy, stwa, stda,
   only give the related comments for them).

 - let it pass compiling.

Or, can we find related members in our gdb mailing list which has parisc
environments?

>> ---
>>  gdb/hppa-tdep.c | 111 +++++++++++++++++++++++++++++++++++++++++++-------------
>>  1 file changed, 85 insertions(+), 26 deletions(-)
>>
>> diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
>> index 627f31a..4f52e43 100644
>> --- a/gdb/hppa-tdep.c
>> +++ b/gdb/hppa-tdep.c
>> @@ -1376,37 +1376,96 @@ is_branch (unsigned long inst)
>>  }
>>  
>>  /* Return the register number for a GR which is saved by INST or
>> -   zero it INST does not save a GR.  */
>> +   zero it INST does not save a GR.
> 
> While changing this, can you change "zero it" -> "zero if".
> 

OK, thanks.

>> +     Store a word or doubleword using an absolute memory address formed
>> +     using short or long displace- ment or indexed
>                             ^^^^^^^^^^^^^^
> 
> "displace- ment" -> "displacement".
> 

OK, thanks.

>> +static int
>> +inst_saves_gr (unsigned long inst)
>> +{
>> +  switch ((inst >> 26) & 0x0f)
>> +    {
>> +      case 0x03:
>> +	switch ((inst >> 6) & 0x0f)
>> +	  {
>> +	    case 0x08:
>> +	    case 0x09:
>> +	    case 0x0a:
>> +	    case 0x0b:
>> +	    case 0x0c:
>> +	    case 0x0d:
>> +	    case 0x0e:
>> +	    case 0x0f:
>> +	      break;
>> +	    default:
>> +	      return 0;
>> +	  }
>> +	/* Fall through */
>> +      case 0x18:
>> +      case 0x19:
>> +      case 0x1a:
>> +      case 0x1b:
>> +      case 0x1c:
>> +      /* no 0x1d or 0x1e -- according to parisc 2.0 document */
>> +      case 0x1f:
>> +	return hppa_extract_5R_store (inst);
>> +      default:
>> +	return 0;
> 
> Quite honestly, I find your code quite confusing because of
> the fall-through. It's up to you, but wouldn't it be clearer
> if you had "hppa_extract_5R_store (inst)" instead of "break" +
> the "/* Fall through */" ?
> 

OK, thanks, if still use the switch statement for path v2, I will remove
the /* Fall through */.

Thanks.
Joel Brobecker Dec. 15, 2014, 12:49 p.m. UTC | #3
> Excuse me, I have no related test environments for parisc either. Maybe
> I can try to construct the related virtual environments for it, but I am
> still not quite sure whether it is enough.
> 
> Can we change to another way for it:
> 
>  - try to keep the original code no touch.
> 
>  - only fix the related typo issues according to the related documents,
>    do not add new features (e.g. do not check stby, stbdy, stwa, stda,
>    only give the related comments for them).
> 
>  - let it pass compiling.
> 
> Or, can we find related members in our gdb mailing list which has parisc
> environments?

I think finding people who can test your change would be ideal,
but is not required. I was just making it clear what my review
could bring, or rather not bring. I think it's fine to increase
the scope of the routine as you've been doing, as I think the risk
of disturbing currently supported instructions is small.

I am curious - and you do not have to reply if you do not want to -,
how did you get involved in this change? If you have no testing
environment, it probably means you're not using the code.  What
made you decide to try to fix it?
Chen Gang Dec. 15, 2014, 2:24 p.m. UTC | #4
On 12/15/2014 08:49 PM, Joel Brobecker wrote:
>> Excuse me, I have no related test environments for parisc either. Maybe
>> I can try to construct the related virtual environments for it, but I am
>> still not quite sure whether it is enough.
>>
>> Can we change to another way for it:
>>
>>  - try to keep the original code no touch.
>>
>>  - only fix the related typo issues according to the related documents,
>>    do not add new features (e.g. do not check stby, stbdy, stwa, stda,
>>    only give the related comments for them).
>>
>>  - let it pass compiling.
>>
>> Or, can we find related members in our gdb mailing list which has parisc
>> environments?
> 
> I think finding people who can test your change would be ideal,
> but is not required. I was just making it clear what my review
> could bring, or rather not bring. I think it's fine to increase
> the scope of the routine as you've been doing, as I think the risk
> of disturbing currently supported instructions is small.
> 

OK, thanks.

> I am curious - and you do not have to reply if you do not want to -,
> how did you get involved in this change? If you have no testing
> environment, it probably means you're not using the code.  What
> made you decide to try to fix it?
> 

When I compiling binutils, and find the compiler warning, then try to
fix it with other members. I have no environments, not familiar with
parisc, no enough time resources ... but I should still try my best.

Originally, I worked for coredump analysing (kdb for Linux kernel, gdb
for user mode C++ program) -- which have no test environments, either
not familiar many things, but the end time point is sensitive ...

At present, after I really touch the open source in details, I know:

 - Most of persons and companies (include me) have already get benefit
   from open source, especially fundamental software (e.g. binutils,
   gdb), but most of them do not contribute back to open source.

 - But open source still continue, and still benefit to most of persons
   and companies.

 - What I have done is just only try to contribute back to open source.


Thanks.
diff mbox

Patch

diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index 627f31a..4f52e43 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -1376,37 +1376,96 @@  is_branch (unsigned long inst)
 }
 
 /* Return the register number for a GR which is saved by INST or
-   zero it INST does not save a GR.  */
+   zero it INST does not save a GR.
 
-static int
-inst_saves_gr (unsigned long inst)
-{
-  /* Does it look like a stw?  */
-  if ((inst >> 26) == 0x1a || (inst >> 26) == 0x1b
-      || (inst >> 26) == 0x1f
-      || ((inst >> 26) == 0x1f
-	  && ((inst >> 6) == 0xa)))
-    return hppa_extract_5R_store (inst);
+   Referenced from:
 
-  /* Does it look like a std?  */
-  if ((inst >> 26) == 0x1c
-      || ((inst >> 26) == 0x03
-	  && ((inst >> 6) & 0xf) == 0xb))
-    return hppa_extract_5R_store (inst);
+     parisc 1.1:
+     https://parisc.wiki.kernel.org/images-parisc/6/68/Pa11_acd.pdf
 
-  /* Does it look like a stwm?  GCC & HPC may use this in prologues.  */
-  if ((inst >> 26) == 0x1b)
-    return hppa_extract_5R_store (inst);
+     parisc 2.0:
+     https://parisc.wiki.kernel.org/images-parisc/7/73/Parisc2.0.pdf
 
-  /* Does it look like sth or stb?  HPC versions 9.0 and later use these
-     too.  */
-  if ((inst >> 26) == 0x19 || (inst >> 26) == 0x18
-      || ((inst >> 26) == 0x3
-	  && (((inst >> 6) & 0xf) == 0x8
-	      || (inst >> 6) & 0xf) == 0x9))
-    return hppa_extract_5R_store (inst);
+   For (inst >> 26):
 
-  return 0;
+     The effective memory reference address is formed by the addition
+     of an immediate displacement to a base value.
+
+    - stb: 0x18, store a byte from a general register.
+
+    - sth: 0x19, store a halfword from a general register.
+
+    - stw: 0x1a, store a word from a general register.
+
+    - stwm: 0x1b, store a word from a general register and perform base
+      register modification (2.0 will still treate it as stw).
+
+    - std: 0x1c, store a doubleword from a general register (2.0 only).
+
+    - stw: 0x1f, store a word from a general register (2.0 only).
+
+   For (inst >> 6) when ((inst >> 26) == 0x03):
+
+     The effective memory reference address is formed by the addition
+     of an index value to a base value specified in the instruction.
+
+    - stb: 0x08, store a byte from a general register (1.1 calls stbs).
+
+    - sth: 0x09, store a halfword from a general register (1.1 calls
+      sths).
+
+    - stw: 0x0a, store a word from a general register (1.1 calls stws).
+
+    - std: 0x0b: store a doubleword from a general register (2.0 only)
+
+     Implement fast byte moves (stores) to unaligned word or doubleword
+     destination.
+
+    - stby: 0x0c, for unaligned word (1.1 calls stbys).
+
+    - stdby: 0x0d for unaligned doubleword (2.0 only).
+
+     Store a word or doubleword using an absolute memory address formed
+     using short or long displace- ment or indexed
+
+    - stwa: 0x0e, store a word from a general register to an absolute
+      address (1.0 calls stwas).
+
+    - stda: 0x0f, store a doubleword from a general register to an
+      absolute address (2.0 only).  */
+
+static int
+inst_saves_gr (unsigned long inst)
+{
+  switch ((inst >> 26) & 0x0f)
+    {
+      case 0x03:
+	switch ((inst >> 6) & 0x0f)
+	  {
+	    case 0x08:
+	    case 0x09:
+	    case 0x0a:
+	    case 0x0b:
+	    case 0x0c:
+	    case 0x0d:
+	    case 0x0e:
+	    case 0x0f:
+	      break;
+	    default:
+	      return 0;
+	  }
+	/* Fall through */
+      case 0x18:
+      case 0x19:
+      case 0x1a:
+      case 0x1b:
+      case 0x1c:
+      /* no 0x1d or 0x1e -- according to parisc 2.0 document */
+      case 0x1f:
+	return hppa_extract_5R_store (inst);
+      default:
+	return 0;
+    }
 }
 
 /* Return the register number for a FR which is saved by INST or