Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* RE: H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
@ 2003-12-10  5:06 Dhananjay R. Deshpande
  2003-12-10 17:10 ` Andrew Cagney
  0 siblings, 1 reply; 15+ messages in thread
From: Dhananjay R. Deshpande @ 2003-12-10  5:06 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Andrew Cagney, Michael Snyder, gdb-patches

Hi,

If you can, please check in the patch. My CVS access problem is not yet solved. I had put a request to update my public key to overseers but its not done. http://sources.redhat.com/ml/overseers/2003-q4/msg00240.html


Regards,
Dhananjay

> -----Original Message-----
> From: Andrew Cagney [mailto:cagney@gnu.org]
> Sent: Wednesday, December 03, 2003 9:55 AM
> To: Dhananjay R. Deshpande
> Cc: Andrew Cagney; Michael Snyder; gdb-patches@sources.redhat.com
> Subject: Re: H8300 Patch - Fix GDB crash problem when object file of
> different H8 cpu is loaded
> 
> 
> > Hi Andrew,
> > 
> > 
> >> so that the "current_gdbarch" is passed explicitly as a 
> >> parameter making 
> >> the call:
> >>      is_h8300smode (current_gdbarch)
> > 
> > 
> > Done.
> > 
> > I also made these functions static and for remote-e7000, 
> used TARGET_ARCHITECTURE->mach for NUM_REALREGS.
> > 
> > Based on your email, I have applied for cvs account and put 
> your email address for approval.
> > 
> > Please find updated patch below.
> 
> Thanks.
> 
> Andrew
> 
> 
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
  2003-12-10  5:06 H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded Dhananjay R. Deshpande
@ 2003-12-10 17:10 ` Andrew Cagney
  0 siblings, 0 replies; 15+ messages in thread
From: Andrew Cagney @ 2003-12-10 17:10 UTC (permalink / raw)
  To: Dhananjay R. Deshpande, Michael Snyder; +Cc: Andrew Cagney, gdb-patches

> Hi,
> 
> If you can, please check in the patch. My CVS access problem is not yet solved. I had put a request to update my public key to overseers but its not done. http://sources.redhat.com/ml/overseers/2003-q4/msg00240.html

Michael, can you please handle this.

Andrew



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
  2003-12-17  5:59 Dhananjay R. Deshpande
@ 2003-12-17 19:32 ` Michael Snyder
  0 siblings, 0 replies; 15+ messages in thread
From: Michael Snyder @ 2003-12-17 19:32 UTC (permalink / raw)
  To: Dhananjay R. Deshpande; +Cc: Andrew Cagney, Andrew Cagney, gdb-patches

Dhananjay R. Deshpande wrote:
> Hi Michael,
> 
> 
>>I'm afraid you need to un-commit it.  This breaks gdb.
>>It no longer works with the simulator for h8s, h8h, or h8sx.
> 
> 
> I did make sure that GDB is working with simulator for H8/300, H8/300H and H8S.
> I am appending the gdb log where output file of each target is loaded in GDB
 > with simulator as target.

Well that's weird -- we must be doing something differently.
I am definitely seeing it fail.

When I build the testcase "movw.s" for "h", "s", or "sx" machine,
and then debug it like this:

	% sh-elf-gdb -nw movw.s.x
	(gdb) target sim
	(gdb) load

I find that GDB knows the target is h8300h (or whatever),
but sim does not.  None of the sim "mode" variables is ever set.


>>As I mentioned earlier in this thread, these global variables
>>that you've replaced are shared between gdb and the sim.  The
>>sim depends on them.  You've split them into essentially
>>gdb's copy and the sim's copy, but now the sim's copy is
>>never getting initialized, becuase it was gdb that
>>initialized the shared ones.  That's why they were shared.
>>
> 
> 
> The SIM sets these variables in set_h8300h called from sim_load. The GDB calls sim_load.

Ah.  Well, sim_load fails.  GDB does not send a bfd pointer,
it only sends the path to the executable file.  Since "abfd"
is null, sim_load tries to open the file with the following call:

   if (abfd != NULL)
     prog_bfd = abfd;
   else
     prog_bfd = bfd_openr (prog, "coff-h8300");

Note the "coff-h8300" parameter.  Since the file isn't coff,
this call returns NULL, and therefore set_h8300h is never
called.



> If you still think that patch should be reverted, I will do that.

Well, I'd like to know what you are doing differently
that makes it work for you, but then I'd like to see
the problem where it fails to work addressed.

By the way -- the symptom for "not working" is that
GDB and SIM disagree about the size of registers,
specifically the PC.  GDB thinks the PC is 4 bytes,
but SIM thinks it is 2 bytes.  Therefore when we
hit a breakpoint at, say, 0x1000, the register value
gets displaced by 16 bits, and comes back as 0x10000000.





^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
@ 2003-12-17  5:59 Dhananjay R. Deshpande
  2003-12-17 19:32 ` Michael Snyder
  0 siblings, 1 reply; 15+ messages in thread
From: Dhananjay R. Deshpande @ 2003-12-17  5:59 UTC (permalink / raw)
  To: Michael Snyder; +Cc: Andrew Cagney, Andrew Cagney, gdb-patches


Hi Michael,

> 
> I'm afraid you need to un-commit it.  This breaks gdb.
> It no longer works with the simulator for h8s, h8h, or h8sx.

I did make sure that GDB is working with simulator for H8/300, H8/300H and H8S.
I am appending the gdb log where output file of each target is loaded in GDB with simulator as target.

> 
> As I mentioned earlier in this thread, these global variables
> that you've replaced are shared between gdb and the sim.  The
> sim depends on them.  You've split them into essentially
> gdb's copy and the sim's copy, but now the sim's copy is
> never getting initialized, becuase it was gdb that
> initialized the shared ones.  That's why they were shared.
> 

The SIM sets these variables in set_h8300h called from sim_load. The GDB calls sim_load.
 
If you still think that patch should be reverted, I will do that.

[dhananjayd@Linuxsrv5 gnu]$ ~/gdbh8/bin/h8300-elf-gdb
GNU gdb 2003-12-17-cvs
Copyright 2003 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "--host=i686-pc-linux-gnu --target=h8300-elf".
(gdb) file h8.out
Reading symbols from h8.out...done.
(gdb) target sim
Connected to the simulator.
(gdb) lo
Loading section .init, size 0xa vma 0x100
Loading section .text, size 0xab82 vma 0x10c
Loading section .fini, size 0x6 vma 0xac8e
Loading section .rodata, size 0x30c vma 0xac94
Loading section .data, size 0x41a vma 0xafa0
Loading section .ctors, size 0x4 vma 0xb3ba
Loading section .dtors, size 0x4 vma 0xb3be
Loading section .jcr, size 0x2 vma 0xb3c2
Start address 0x10c
Transfer rate: 366096 bits in <1 sec.
(gdb) r
Starting program: /user/dhananjayd/gnu/h8.out
Hello 1,2,3

Program exited normally.
(gdb) show architecture
The target architecture is set automatically (currently h8300)
(gdb) file h8h.out
A program is being debugged already.  Kill it? (y or n) y

Load new symbol table from "h8h.out"? (y or n) y
Reading symbols from h8h.out...done.
(gdb) target sim
Connected to the simulator.
(gdb) lo
Loading section .init, size 0xa vma 0x100
Loading section .text, size 0x9052 vma 0x10c
Loading section .fini, size 0x6 vma 0x915e
Loading section .rodata, size 0x3e0 vma 0x9164
Loading section .data, size 0x754 vma 0x9544
Loading section .ctors, size 0x8 vma 0x9c98
Loading section .dtors, size 0x8 vma 0x9ca0
Loading section .jcr, size 0x4 vma 0x9ca8
Start address 0x10c
Transfer rate: 318800 bits in <1 sec.
(gdb) r
Starting program: /user/dhananjayd/gnu/h8h.out
Hello 1,2,3

Program exited normally.
(gdb) show architecture
The target architecture is set automatically (currently h8300h)
(gdb) file h8s.out
A program is being debugged already.  Kill it? (y or n) y

Load new symbol table from "h8s.out"? (y or n) y
Reading symbols from h8s.out...done.
(gdb) target sim
Connected to the simulator.
(gdb) lo
Loading section .init, size 0xa vma 0x100
Loading section .text, size 0x8df0 vma 0x10c
Loading section .fini, size 0x6 vma 0x8efc
Loading section .rodata, size 0x3e0 vma 0x8f04
Loading section .data, size 0x754 vma 0x92e4
Loading section .ctors, size 0x8 vma 0x9a38
Loading section .dtors, size 0x8 vma 0x9a40
Loading section .jcr, size 0x4 vma 0x9a48
Start address 0x10c
Transfer rate: 313920 bits in <1 sec.
(gdb) r
Starting program: /user/dhananjayd/gnu/h8s.out
Hello 1,2,3

Program exited normally.
(gdb) show architecture
The target architecture is set automatically (currently h8300s)
(gdb)


Regards,
Dhananjay

> -----Original Message-----
> From: Michael Snyder [mailto:msnyder@redhat.com]
> Sent: Wednesday, December 17, 2003 5:27 AM
> To: Dhananjay R. Deshpande
> Cc: Andrew Cagney; Andrew Cagney; gdb-patches@sources.redhat.com
> Subject: Re: H8300 Patch - Fix GDB crash problem when object file of
> different H8 cpu is loaded
> 
> 
> Dhananjay R. Deshpande wrote:
> > Thanks.
> > 
> > Commited.
> 
> I'm afraid you need to un-commit it.  This breaks gdb.
> It no longer works with the simulator for h8s, h8h, or h8sx.
> 
> As I mentioned earlier in this thread, these global variables
> that you've replaced are shared between gdb and the sim.  The
> sim depends on them.  You've split them into essentially
> gdb's copy and the sim's copy, but now the sim's copy is
> never getting initialized, becuase it was gdb that
> initialized the shared ones.  That's why they were shared.
> 
> To complete this job, you need to work out an interface
> that will allow the sim to get this information from gdb.
> 
> > 
> > -Dhannajay
> > 
> > 
> >>-----Original Message-----
> >>From: Andrew Cagney [mailto:cagney@gnu.org]
> >>Sent: Wednesday, December 10, 2003 10:41 PM
> >>To: Dhananjay R. Deshpande; Michael Snyder
> >>Cc: Andrew Cagney; gdb-patches@sources.redhat.com
> >>Subject: Re: H8300 Patch - Fix GDB crash problem when object file of
> >>different H8 cpu is loaded
> >>
> >>
> >>
> >>>Hi,
> >>>
> >>>If you can, please check in the patch. My CVS access 
> >>
> >>problem is not yet solved. I had put a request to update my 
> >>public key to overseers but its not done. 
> >>http://sources.redhat.com/ml/overseers/2003-q4/msg00240.html
> >>
> >>Michael, can you please handle this.
> >>
> >>Andrew
> >>
> >>
> > 
> > 
> > 
> 
> 
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
  2003-12-11  6:52 Dhananjay R. Deshpande
@ 2003-12-16 23:56 ` Michael Snyder
  0 siblings, 0 replies; 15+ messages in thread
From: Michael Snyder @ 2003-12-16 23:56 UTC (permalink / raw)
  To: Dhananjay R. Deshpande; +Cc: Andrew Cagney, Andrew Cagney, gdb-patches

Dhananjay R. Deshpande wrote:
> Thanks.
> 
> Commited.

I'm afraid you need to un-commit it.  This breaks gdb.
It no longer works with the simulator for h8s, h8h, or h8sx.

As I mentioned earlier in this thread, these global variables
that you've replaced are shared between gdb and the sim.  The
sim depends on them.  You've split them into essentially
gdb's copy and the sim's copy, but now the sim's copy is
never getting initialized, becuase it was gdb that
initialized the shared ones.  That's why they were shared.

To complete this job, you need to work out an interface
that will allow the sim to get this information from gdb.

> 
> -Dhannajay
> 
> 
>>-----Original Message-----
>>From: Andrew Cagney [mailto:cagney@gnu.org]
>>Sent: Wednesday, December 10, 2003 10:41 PM
>>To: Dhananjay R. Deshpande; Michael Snyder
>>Cc: Andrew Cagney; gdb-patches@sources.redhat.com
>>Subject: Re: H8300 Patch - Fix GDB crash problem when object file of
>>different H8 cpu is loaded
>>
>>
>>
>>>Hi,
>>>
>>>If you can, please check in the patch. My CVS access 
>>
>>problem is not yet solved. I had put a request to update my 
>>public key to overseers but its not done. 
>>http://sources.redhat.com/ml/overseers/2003-q4/msg00240.html
>>
>>Michael, can you please handle this.
>>
>>Andrew
>>
>>
> 
> 
> 



^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
@ 2003-12-11  6:52 Dhananjay R. Deshpande
  2003-12-16 23:56 ` Michael Snyder
  0 siblings, 1 reply; 15+ messages in thread
From: Dhananjay R. Deshpande @ 2003-12-11  6:52 UTC (permalink / raw)
  To: Andrew Cagney, Michael Snyder; +Cc: Andrew Cagney, gdb-patches

Thanks.

Commited.

-Dhannajay

> -----Original Message-----
> From: Andrew Cagney [mailto:cagney@gnu.org]
> Sent: Wednesday, December 10, 2003 10:41 PM
> To: Dhananjay R. Deshpande; Michael Snyder
> Cc: Andrew Cagney; gdb-patches@sources.redhat.com
> Subject: Re: H8300 Patch - Fix GDB crash problem when object file of
> different H8 cpu is loaded
> 
> 
> > Hi,
> > 
> > If you can, please check in the patch. My CVS access 
> problem is not yet solved. I had put a request to update my 
> public key to overseers but its not done. 
> http://sources.redhat.com/ml/overseers/2003-q4/msg00240.html
> 
> Michael, can you please handle this.
> 
> Andrew
> 
> 
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
  2003-12-02 13:18 Dhananjay R. Deshpande
@ 2003-12-03  4:24 ` Andrew Cagney
  0 siblings, 0 replies; 15+ messages in thread
From: Andrew Cagney @ 2003-12-03  4:24 UTC (permalink / raw)
  To: Dhananjay R. Deshpande; +Cc: Andrew Cagney, Michael Snyder, gdb-patches

> Hi Andrew,
> 
> 
>> so that the "current_gdbarch" is passed explicitly as a 
>> parameter making 
>> the call:
>>      is_h8300smode (current_gdbarch)
> 
> 
> Done.
> 
> I also made these functions static and for remote-e7000, used TARGET_ARCHITECTURE->mach for NUM_REALREGS.
> 
> Based on your email, I have applied for cvs account and put your email address for approval.
> 
> Please find updated patch below.

Thanks.

Andrew



^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
@ 2003-12-02 13:18 Dhananjay R. Deshpande
  2003-12-03  4:24 ` Andrew Cagney
  0 siblings, 1 reply; 15+ messages in thread
From: Dhananjay R. Deshpande @ 2003-12-02 13:18 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Andrew Cagney, Michael Snyder, gdb-patches

Hi Andrew,

> so that the "current_gdbarch" is passed explicitly as a 
> parameter making 
> the call:
>      is_h8300smode (current_gdbarch)

Done.

I also made these functions static and for remote-e7000, used TARGET_ARCHITECTURE->mach for NUM_REALREGS.

Based on your email, I have applied for cvs account and put your email address for approval.

Please find updated patch below.

Regards,
Dhananjay

gdb/Changelog -

2003-12-02  Dhananjay Deshpande  <dhananjayd@kpitcummins.com>

        * config/h8300/tm-h8300.h (h8300hmode): Remove.
        (h8300hmode): Likewise.
        (h8300smode): Likewise.
        (h8300sxmode): Likewise.
        (h8300_normal_mode): Likewise.
        (GDB_TARGET_IS_H8300): Likewise.
        (NUM_REALREGS): Use TARGET_ARCHITECTURE->mach instead of global.
        * h8300-tdep.c (is_h8300hmode): New function.
        (is_h8300smode): New function.
        (is_h8300sxmode): New function.
        (is_h8300_normal_mode): New function.
        (BINWORD): Use new functions.
        (h8300_examine_prologue): Likewise.
        (h8300_print_register): Likewise.
        (h8300_print_registers_info): Likewise.
        (h8300_register_type): Likewise.
        (h8300_gdbarch_init): Remove use of globals like h8300hmode.
        * remote-e7000.c (e7000_open): Remove use of GDB_TARGET_IS_H8300.
        (e7000_fetch_registers): Use TARGET_ARCHITECTURE->mach instead of global.
        (e7000_wait): Use TARGET_ARCHITECTURE->mach instead of global.


sim/Changelog

2003-12-02  Dhananjay Deshpande  <dhananjayd@kpitcummins.com>

        * h8300/compile.c (set_h8300h): Initialize globals to zero.

============================================================================
diff -upr --strip-trailing-cr gdb+dejagnu-20031114.orig/gdb/config/h8300/tm-h8300.h gdb+dejagnu-20031114/gdb/config/h8300/tm-h8300.h
--- gdb+dejagnu-20031114.orig/gdb/config/h8300/tm-h8300.h	2003-10-17 18:13:06.000000000 +0530
+++ gdb+dejagnu-20031114/gdb/config/h8300/tm-h8300.h	2003-12-02 17:18:58.000000000 +0530
@@ -20,20 +20,13 @@
    Boston, MA 02111-1307, USA.  */
 /* Contributed by Steve Chamberlain sac@cygnus.com */
 
-/* NOTE: ezannoni 2000-07-18: these variables are part of sim, defined
-   in sim/h8300/compile.c.  They really should not be used this
-   way. Because of this we cannot get rid of the macro
-   GDB_TARGET_IS_H8300 in remote-e7000.c */
-extern int h8300hmode;
-extern int h8300smode;
-extern int h8300_normal_mode; /* 1 - Normal Mode , 0 - Advanced mode */
-extern int h8300sxmode;
-#define GDB_TARGET_IS_H8300
-
 /* Needed for remote.c */
 #define DEPRECATED_REMOTE_BREAKPOINT { 0x57, 0x30}		/* trapa #3 */
 /* Needed for remote-hms.c */
 #define CCR_REGNUM 8
 /* Needed for remote-e7000.c */
-#define NUM_REALREGS (h8300smode?11:10)
+#define NUM_REALREGS ((TARGET_ARCHITECTURE->mach == bfd_mach_h8300s || \
+		        TARGET_ARCHITECTURE->mach == bfd_mach_h8300sn || \
+		        TARGET_ARCHITECTURE->mach == bfd_mach_h8300sx || \
+		        TARGET_ARCHITECTURE->mach == bfd_mach_h8300sxn) ? 11 : 10)
 
diff -upr --strip-trailing-cr gdb+dejagnu-20031114.orig/gdb/h8300-tdep.c gdb+dejagnu-20031114/gdb/h8300-tdep.c
--- gdb+dejagnu-20031114.orig/gdb/h8300-tdep.c	2003-10-17 18:13:04.000000000 +0530
+++ gdb+dejagnu-20031114/gdb/h8300-tdep.c	2003-12-02 17:28:07.000000000 +0530
@@ -49,7 +49,14 @@ enum
   h8300h_reg_size = 4,
   h8300_max_reg_size = 4,
 };
-#define BINWORD (h8300hmode && !h8300_normal_mode ? h8300h_reg_size : h8300_reg_size)
+
+static int is_h8300hmode (struct gdbarch *gdbarch);
+static int is_h8300smode (struct gdbarch *gdbarch);
+static int is_h8300sxmode (struct gdbarch *gdbarch);
+static int is_h8300_normal_mode (struct gdbarch *gdbarch);
+
+#define BINWORD (is_h8300hmode (current_gdbarch) && \
+		  !is_h8300_normal_mode (current_gdbarch) ? h8300h_reg_size : h8300_reg_size)
 
 enum gdb_regnum
 {
@@ -350,7 +357,8 @@ h8300_examine_prologue (CORE_ADDR ip, CO
     }
 
   /* If the PC isn't valid, quit now.  */
-  if (ip == 0 || ip & (h8300hmode && !h8300_normal_mode ? ~0xffffff : ~0xffff))
+  if (ip == 0 || ip & (is_h8300hmode (current_gdbarch) &&
+			 !is_h8300_normal_mode (current_gdbarch) ? ~0xffffff : ~0xffff))
     return 0;
 
   next_ip = h8300_next_prologue_insn (ip, limit, &insn_word);
@@ -947,7 +955,8 @@ h8300_print_register (struct gdbarch *gd
   rval = get_frame_register_signed (frame, regno);
 
   fprintf_filtered (file, "%-14s ", name);
-  if (regno == E_PSEUDO_CCR_REGNUM || (regno == E_PSEUDO_EXR_REGNUM && h8300smode))
+  if (regno == E_PSEUDO_CCR_REGNUM ||
+       (regno == E_PSEUDO_EXR_REGNUM && is_h8300smode (current_gdbarch)))
     {
       fprintf_filtered (file, "0x%02x        ", (unsigned char)rval);
       print_longest (file, 'u', 1, rval);
@@ -996,7 +1005,7 @@ h8300_print_register (struct gdbarch *gd
       if ((Z | (N ^ V)) == 1)
 	fprintf_filtered (file, "<= ");
     }
-  else if (regno == E_PSEUDO_EXR_REGNUM && h8300smode)
+  else if (regno == E_PSEUDO_EXR_REGNUM && is_h8300smode (current_gdbarch))
     {
       /* EXR register */
       unsigned char l = rval & 0xff;
@@ -1019,10 +1028,10 @@ h8300_print_registers_info (struct gdbar
 	h8300_print_register (gdbarch, file, frame, regno);
       h8300_print_register (gdbarch, file, frame, E_PSEUDO_CCR_REGNUM);
       h8300_print_register (gdbarch, file, frame, E_PC_REGNUM);
-      if (h8300smode)
+      if (is_h8300smode (current_gdbarch))
         {
 	  h8300_print_register (gdbarch, file, frame, E_PSEUDO_EXR_REGNUM);
-	  if (h8300sxmode)
+	  if (is_h8300sxmode (current_gdbarch))
 	    {
 	      h8300_print_register (gdbarch, file, frame, E_SBR_REGNUM);
 	      h8300_print_register (gdbarch, file, frame, E_VBR_REGNUM);
@@ -1044,7 +1053,7 @@ h8300_print_registers_info (struct gdbar
     {
       if (regno == E_CCR_REGNUM)
         h8300_print_register (gdbarch, file, frame, E_PSEUDO_CCR_REGNUM);
-      else if (regno == E_PSEUDO_EXR_REGNUM && h8300smode)
+      else if (regno == E_PSEUDO_EXR_REGNUM && is_h8300smode (current_gdbarch))
 	h8300_print_register (gdbarch, file, frame, E_PSEUDO_EXR_REGNUM);
       else
 	h8300_print_register (gdbarch, file, frame, regno);
@@ -1078,7 +1087,7 @@ h8300_register_type (struct gdbarch *gdb
 	      return builtin_type_uint8;
 	    else if (regno == E_PSEUDO_EXR_REGNUM)
 	      return builtin_type_uint8;
-	    else if (h8300hmode)
+	    else if (is_h8300hmode (current_gdbarch))
 	      return builtin_type_int32;
 	    else
 	      return builtin_type_int16;
@@ -1192,9 +1201,6 @@ h8300_gdbarch_init (struct gdbarch_info 
   switch (info.bfd_arch_info->mach)
     {
     case bfd_mach_h8300:
-      h8300sxmode = 0;
-      h8300smode = 0;
-      h8300hmode = 0;
       set_gdbarch_num_regs (gdbarch, 13);
       set_gdbarch_num_pseudo_regs (gdbarch, 1);
       set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
@@ -1210,9 +1216,6 @@ h8300_gdbarch_init (struct gdbarch_info 
       break;
     case bfd_mach_h8300h:
     case bfd_mach_h8300hn:
-      h8300sxmode = 0;
-      h8300smode = 0;
-      h8300hmode = 1;
       set_gdbarch_num_regs (gdbarch, 13);
       set_gdbarch_num_pseudo_regs (gdbarch, 1);
       set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
@@ -1222,13 +1225,11 @@ h8300_gdbarch_init (struct gdbarch_info 
       set_gdbarch_register_name (gdbarch, h8300_register_name);
       if(info.bfd_arch_info->mach != bfd_mach_h8300hn)
         {
-          h8300_normal_mode = 0;
           set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
         }
       else
         {
-          h8300_normal_mode = 1;
           set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
         }
@@ -1238,9 +1239,6 @@ h8300_gdbarch_init (struct gdbarch_info 
       break;
     case bfd_mach_h8300s:
     case bfd_mach_h8300sn:
-      h8300sxmode = 0;
-      h8300smode = 1;
-      h8300hmode = 1;
       set_gdbarch_num_regs (gdbarch, 16);
       set_gdbarch_num_pseudo_regs (gdbarch, 2);
       set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
@@ -1250,13 +1248,11 @@ h8300_gdbarch_init (struct gdbarch_info 
       set_gdbarch_register_name (gdbarch, h8300s_register_name);
       if(info.bfd_arch_info->mach != bfd_mach_h8300sn)
         {
-          h8300_normal_mode = 0;
           set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
         }
       else
         {
-          h8300_normal_mode = 1;
           set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
         }
@@ -1266,9 +1262,6 @@ h8300_gdbarch_init (struct gdbarch_info 
       break;
     case bfd_mach_h8300sx:
     case bfd_mach_h8300sxn:
-      h8300sxmode = 1;
-      h8300smode = 1;
-      h8300hmode = 1;
       set_gdbarch_num_regs (gdbarch, 18);
       set_gdbarch_num_pseudo_regs (gdbarch, 2);
       set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
@@ -1278,13 +1271,11 @@ h8300_gdbarch_init (struct gdbarch_info 
       set_gdbarch_register_name (gdbarch, h8300sx_register_name);
       if(info.bfd_arch_info->mach != bfd_mach_h8300sxn)
         {
-          h8300_normal_mode = 0;
           set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
         }
       else
         {
-          h8300_normal_mode = 1;
           set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
         }
@@ -1370,3 +1361,39 @@ _initialize_h8300_tdep (void)
 {
   register_gdbarch_init (bfd_arch_h8300, h8300_gdbarch_init);
 }
+
+static int
+is_h8300hmode (struct gdbarch *gdbarch)
+{
+  return gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300sx
+	 || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300sxn
+	 || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300s
+	 || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300sn
+	 || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300h
+	 || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300hn;
+}
+
+static int
+is_h8300smode (struct gdbarch *gdbarch)
+{
+  return gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300sx
+	 || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300sxn
+	 || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300s
+	 || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300sn;
+}
+
+static int
+is_h8300sxmode (struct gdbarch *gdbarch)
+{
+  return gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300sx
+	 || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300sxn;
+}
+
+static int
+is_h8300_normal_mode (struct gdbarch *gdbarch)
+{
+  return gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300sxn
+	 || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300sn
+	 || gdbarch_bfd_arch_info (gdbarch)->mach == bfd_mach_h8300hn;
+}
+
diff -upr --strip-trailing-cr gdb+dejagnu-20031114.orig/gdb/remote-e7000.c gdb+dejagnu-20031114/gdb/remote-e7000.c
--- gdb+dejagnu-20031114.orig/gdb/remote-e7000.c	2003-10-10 12:43:10.000000000 +0530
+++ gdb+dejagnu-20031114/gdb/remote-e7000.c	2003-12-01 16:18:05.000000000 +0530
@@ -657,10 +657,6 @@ e7000_open (char *args, int from_tty)
     }
   serial_raw (e7000_desc);
 
-#ifdef GDB_TARGET_IS_H8300
-  h8300hmode = 1;
-#endif
-
   /* Start the remote connection; if error (0), discard this target.
      In particular, if the user quits, be sure to discard it
      (we'd be in an inconsistent state otherwise).  */
@@ -909,15 +905,18 @@ e7000_fetch_registers (void)
 	  wanted = want_sh3;
 	}
     }
-#ifdef GDB_TARGET_IS_H8300
   if (TARGET_ARCHITECTURE->arch == bfd_arch_h8300)
     {
-      if (h8300smode)
-	wanted = want_h8300s;
-      else
-	wanted = want_h8300h;
+      wanted = want_h8300h;
+      switch (TARGET_ARCHITECTURE->mach)
+	{
+	case bfd_mach_h8300s:
+	case bfd_mach_h8300sn:
+	case bfd_mach_h8300sx:
+	case bfd_mach_h8300sxn:
+	  wanted = want_h8300s;
+	}
     }
-#endif
 
   fetch_regs_from_dump (gch, wanted);
 
@@ -2046,15 +2045,18 @@ e7000_wait (ptid_t ptid, struct target_w
 	  wanted_nopc = want_nopc_sh3;
 	}
     }
-#ifdef GDB_TARGET_IS_H8300
   if (TARGET_ARCHITECTURE->arch == bfd_arch_h8300)
     {
-      if (h8300smode)
-	wanted_nopc = want_nopc_h8300s;
-      else
-	wanted_nopc = want_nopc_h8300h;
+      wanted_nopc = want_nopc_h8300h;
+      switch (TARGET_ARCHITECTURE->mach)
+	{
+	case bfd_mach_h8300s:
+	case bfd_mach_h8300sn:
+	case bfd_mach_h8300sx:
+	case bfd_mach_h8300sxn:
+	  wanted_nopc = want_nopc_h8300s;
+	}
     }
-#endif
   fetch_regs_from_dump (gch, wanted_nopc);
 
   /* And supply the extra ones the simulator uses */
diff -upr --strip-trailing-cr gdb+dejagnu-20031114.orig/sim/h8300/compile.c gdb+dejagnu-20031114/sim/h8300/compile.c
--- gdb+dejagnu-20031114.orig/sim/h8300/compile.c	2003-10-17 18:15:56.000000000 +0530
+++ gdb+dejagnu-20031114/sim/h8300/compile.c	2003-11-27 15:20:43.000000000 +0530
@@ -4930,6 +4930,8 @@ set_h8300h (unsigned long machine)
      This function being replaced by a sim_open:ARGV configuration
      option.  */
 
+  h8300hmode = h8300smode = h8300sxmode = h8300_normal_mode = 0;
+
   if (machine == bfd_mach_h8300sx || machine == bfd_mach_h8300sxn)
     h8300sxmode = 1;
 

============================================================================
> -----Original Message-----
> From: Andrew Cagney [mailto:cagney@gnu.org]
> Sent: Monday, December 01, 2003 10:56 PM
> To: Dhananjay R. Deshpande
> Cc: Andrew Cagney; Michael Snyder; gdb-patches@sources.redhat.com
> Subject: Re: H8300 Patch - Fix GDB crash problem when object file of
> different H8 cpu is loaded
> 
> 
> Basicly ok (and thanks),  can you just change these functions:
> 
> > +int
> > +is_h8300smode (void)
> > +{
> > +  return gdbarch_bfd_arch_info (current_gdbarch)->mach == 
> bfd_mach_h8300sx
> > +	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == 
> bfd_mach_h8300sxn
> > +	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == 
> bfd_mach_h8300s
> > +	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == 
> bfd_mach_h8300sn;
> > +}
> > +
> 
> so that the "current_gdbarch" is passed explicitly as a 
> parameter making 
> the call:
>      is_h8300smode (current_gdbarch)
> That will save someone the effort of having to add the 
> parameter later. 
>   It still leaves the task of replacing current_gdbarch with 
> something 
> more local at the call site, but lets leave that as a later pass.
> 
> With that change it's ok to commit.
> 
> Can you also please, as a separate patch (don't forget 
> changelog and to 
> post it), add yourself to the write after approval list.
> 
> Andrew
> 
> 
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
  2003-12-01 12:58 Dhananjay R. Deshpande
@ 2003-12-01 17:26 ` Andrew Cagney
  0 siblings, 0 replies; 15+ messages in thread
From: Andrew Cagney @ 2003-12-01 17:26 UTC (permalink / raw)
  To: Dhananjay R. Deshpande; +Cc: Andrew Cagney, Michael Snyder, gdb-patches

Basicly ok (and thanks),  can you just change these functions:

> +int
> +is_h8300smode (void)
> +{
> +  return gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300sx
> +	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300sxn
> +	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300s
> +	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300sn;
> +}
> +

so that the "current_gdbarch" is passed explicitly as a parameter making 
the call:
     is_h8300smode (current_gdbarch)
That will save someone the effort of having to add the parameter later. 
  It still leaves the task of replacing current_gdbarch with something 
more local at the call site, but lets leave that as a later pass.

With that change it's ok to commit.

Can you also please, as a separate patch (don't forget changelog and to 
post it), add yourself to the write after approval list.

Andrew



^ permalink raw reply	[flat|nested] 15+ messages in thread

* RE: H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
@ 2003-12-01 12:58 Dhananjay R. Deshpande
  2003-12-01 17:26 ` Andrew Cagney
  0 siblings, 1 reply; 15+ messages in thread
From: Dhananjay R. Deshpande @ 2003-12-01 12:58 UTC (permalink / raw)
  To: Andrew Cagney, Michael Snyder; +Cc: gdb-patches

Hi,

I think there is no need to share the variables in GDB & SIM. The Simulator can keep using its variables and for GDB we can have the functions as suggested by Andrew.

We need to use different names to functions as the variable name and function name conflicts.

Please see if the patch below makes sense.

-Dhananjay


diff -upr --strip-trailing-cr gdb+dejagnu-20031114.orig/gdb/config/h8300/tm-h8300.h gdb+dejagnu-20031114/gdb/config/h8300/tm-h8300.h
--- gdb+dejagnu-20031114.orig/gdb/config/h8300/tm-h8300.h	2003-10-17 18:13:06.000000000 +0530
+++ gdb+dejagnu-20031114/gdb/config/h8300/tm-h8300.h	2003-12-01 16:55:44.000000000 +0530
@@ -20,20 +20,15 @@
    Boston, MA 02111-1307, USA.  */
 /* Contributed by Steve Chamberlain sac@cygnus.com */
 
-/* NOTE: ezannoni 2000-07-18: these variables are part of sim, defined
-   in sim/h8300/compile.c.  They really should not be used this
-   way. Because of this we cannot get rid of the macro
-   GDB_TARGET_IS_H8300 in remote-e7000.c */
-extern int h8300hmode;
-extern int h8300smode;
-extern int h8300_normal_mode; /* 1 - Normal Mode , 0 - Advanced mode */
-extern int h8300sxmode;
-#define GDB_TARGET_IS_H8300
-
 /* Needed for remote.c */
 #define DEPRECATED_REMOTE_BREAKPOINT { 0x57, 0x30}		/* trapa #3 */
 /* Needed for remote-hms.c */
 #define CCR_REGNUM 8
 /* Needed for remote-e7000.c */
-#define NUM_REALREGS (h8300smode?11:10)
+#define NUM_REALREGS (is_h8300smode()?11:10)
+
+extern int is_h8300hmode (void);
+extern int is_h8300smode (void);
+extern int is_h8300sxmode (void);
+extern int is_h8300_normal_mode (void);
 
diff -upr --strip-trailing-cr gdb+dejagnu-20031114.orig/gdb/h8300-tdep.c gdb+dejagnu-20031114/gdb/h8300-tdep.c
--- gdb+dejagnu-20031114.orig/gdb/h8300-tdep.c	2003-10-17 18:13:04.000000000 +0530
+++ gdb+dejagnu-20031114/gdb/h8300-tdep.c	2003-12-01 16:55:33.000000000 +0530
@@ -49,7 +49,7 @@ enum
   h8300h_reg_size = 4,
   h8300_max_reg_size = 4,
 };
-#define BINWORD (h8300hmode && !h8300_normal_mode ? h8300h_reg_size : h8300_reg_size)
+#define BINWORD (is_h8300hmode() && !is_h8300_normal_mode() ? h8300h_reg_size : h8300_reg_size)
 
 enum gdb_regnum
 {
@@ -350,7 +350,7 @@ h8300_examine_prologue (CORE_ADDR ip, CO
     }
 
   /* If the PC isn't valid, quit now.  */
-  if (ip == 0 || ip & (h8300hmode && !h8300_normal_mode ? ~0xffffff : ~0xffff))
+  if (ip == 0 || ip & (is_h8300hmode() && !is_h8300_normal_mode() ? ~0xffffff : ~0xffff))
     return 0;
 
   next_ip = h8300_next_prologue_insn (ip, limit, &insn_word);
@@ -947,7 +947,7 @@ h8300_print_register (struct gdbarch *gd
   rval = get_frame_register_signed (frame, regno);
 
   fprintf_filtered (file, "%-14s ", name);
-  if (regno == E_PSEUDO_CCR_REGNUM || (regno == E_PSEUDO_EXR_REGNUM && h8300smode))
+  if (regno == E_PSEUDO_CCR_REGNUM || (regno == E_PSEUDO_EXR_REGNUM && is_h8300smode()))
     {
       fprintf_filtered (file, "0x%02x        ", (unsigned char)rval);
       print_longest (file, 'u', 1, rval);
@@ -996,7 +996,7 @@ h8300_print_register (struct gdbarch *gd
       if ((Z | (N ^ V)) == 1)
 	fprintf_filtered (file, "<= ");
     }
-  else if (regno == E_PSEUDO_EXR_REGNUM && h8300smode)
+  else if (regno == E_PSEUDO_EXR_REGNUM && is_h8300smode())
     {
       /* EXR register */
       unsigned char l = rval & 0xff;
@@ -1019,10 +1019,10 @@ h8300_print_registers_info (struct gdbar
 	h8300_print_register (gdbarch, file, frame, regno);
       h8300_print_register (gdbarch, file, frame, E_PSEUDO_CCR_REGNUM);
       h8300_print_register (gdbarch, file, frame, E_PC_REGNUM);
-      if (h8300smode)
+      if (is_h8300smode())
         {
 	  h8300_print_register (gdbarch, file, frame, E_PSEUDO_EXR_REGNUM);
-	  if (h8300sxmode)
+	  if (is_h8300sxmode())
 	    {
 	      h8300_print_register (gdbarch, file, frame, E_SBR_REGNUM);
 	      h8300_print_register (gdbarch, file, frame, E_VBR_REGNUM);
@@ -1044,7 +1044,7 @@ h8300_print_registers_info (struct gdbar
     {
       if (regno == E_CCR_REGNUM)
         h8300_print_register (gdbarch, file, frame, E_PSEUDO_CCR_REGNUM);
-      else if (regno == E_PSEUDO_EXR_REGNUM && h8300smode)
+      else if (regno == E_PSEUDO_EXR_REGNUM && is_h8300smode())
 	h8300_print_register (gdbarch, file, frame, E_PSEUDO_EXR_REGNUM);
       else
 	h8300_print_register (gdbarch, file, frame, regno);
@@ -1078,7 +1078,7 @@ h8300_register_type (struct gdbarch *gdb
 	      return builtin_type_uint8;
 	    else if (regno == E_PSEUDO_EXR_REGNUM)
 	      return builtin_type_uint8;
-	    else if (h8300hmode)
+	    else if (is_h8300hmode())
 	      return builtin_type_int32;
 	    else
 	      return builtin_type_int16;
@@ -1192,9 +1192,6 @@ h8300_gdbarch_init (struct gdbarch_info 
   switch (info.bfd_arch_info->mach)
     {
     case bfd_mach_h8300:
-      h8300sxmode = 0;
-      h8300smode = 0;
-      h8300hmode = 0;
       set_gdbarch_num_regs (gdbarch, 13);
       set_gdbarch_num_pseudo_regs (gdbarch, 1);
       set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
@@ -1210,9 +1207,6 @@ h8300_gdbarch_init (struct gdbarch_info 
       break;
     case bfd_mach_h8300h:
     case bfd_mach_h8300hn:
-      h8300sxmode = 0;
-      h8300smode = 0;
-      h8300hmode = 1;
       set_gdbarch_num_regs (gdbarch, 13);
       set_gdbarch_num_pseudo_regs (gdbarch, 1);
       set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
@@ -1222,13 +1216,11 @@ h8300_gdbarch_init (struct gdbarch_info 
       set_gdbarch_register_name (gdbarch, h8300_register_name);
       if(info.bfd_arch_info->mach != bfd_mach_h8300hn)
         {
-          h8300_normal_mode = 0;
           set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
         }
       else
         {
-          h8300_normal_mode = 1;
           set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
         }
@@ -1238,9 +1230,6 @@ h8300_gdbarch_init (struct gdbarch_info 
       break;
     case bfd_mach_h8300s:
     case bfd_mach_h8300sn:
-      h8300sxmode = 0;
-      h8300smode = 1;
-      h8300hmode = 1;
       set_gdbarch_num_regs (gdbarch, 16);
       set_gdbarch_num_pseudo_regs (gdbarch, 2);
       set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
@@ -1250,13 +1239,11 @@ h8300_gdbarch_init (struct gdbarch_info 
       set_gdbarch_register_name (gdbarch, h8300s_register_name);
       if(info.bfd_arch_info->mach != bfd_mach_h8300sn)
         {
-          h8300_normal_mode = 0;
           set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
         }
       else
         {
-          h8300_normal_mode = 1;
           set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
         }
@@ -1266,9 +1253,6 @@ h8300_gdbarch_init (struct gdbarch_info 
       break;
     case bfd_mach_h8300sx:
     case bfd_mach_h8300sxn:
-      h8300sxmode = 1;
-      h8300smode = 1;
-      h8300hmode = 1;
       set_gdbarch_num_regs (gdbarch, 18);
       set_gdbarch_num_pseudo_regs (gdbarch, 2);
       set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
@@ -1278,13 +1262,11 @@ h8300_gdbarch_init (struct gdbarch_info 
       set_gdbarch_register_name (gdbarch, h8300sx_register_name);
       if(info.bfd_arch_info->mach != bfd_mach_h8300sxn)
         {
-          h8300_normal_mode = 0;
           set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
         }
       else
         {
-          h8300_normal_mode = 1;
           set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
         }
@@ -1370,3 +1352,39 @@ _initialize_h8300_tdep (void)
 {
   register_gdbarch_init (bfd_arch_h8300, h8300_gdbarch_init);
 }
+
+int
+is_h8300hmode (void)
+{
+  return gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300sx
+	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300sxn
+	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300s
+	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300sn
+	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300h
+	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300hn;
+}
+
+int
+is_h8300smode (void)
+{
+  return gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300sx
+	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300sxn
+	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300s
+	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300sn;
+}
+
+int
+is_h8300sxmode (void)
+{
+  return gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300sx
+	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300sxn;
+}
+
+int
+is_h8300_normal_mode (void)
+{
+  return gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300sxn
+	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300sn
+	 || gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300hn;
+}
+
diff -upr --strip-trailing-cr gdb+dejagnu-20031114.orig/gdb/remote-e7000.c gdb+dejagnu-20031114/gdb/remote-e7000.c
--- gdb+dejagnu-20031114.orig/gdb/remote-e7000.c	2003-10-10 12:43:10.000000000 +0530
+++ gdb+dejagnu-20031114/gdb/remote-e7000.c	2003-12-01 16:18:05.000000000 +0530
@@ -657,10 +657,6 @@ e7000_open (char *args, int from_tty)
     }
   serial_raw (e7000_desc);
 
-#ifdef GDB_TARGET_IS_H8300
-  h8300hmode = 1;
-#endif
-
   /* Start the remote connection; if error (0), discard this target.
      In particular, if the user quits, be sure to discard it
      (we'd be in an inconsistent state otherwise).  */
@@ -909,15 +905,18 @@ e7000_fetch_registers (void)
 	  wanted = want_sh3;
 	}
     }
-#ifdef GDB_TARGET_IS_H8300
   if (TARGET_ARCHITECTURE->arch == bfd_arch_h8300)
     {
-      if (h8300smode)
-	wanted = want_h8300s;
-      else
-	wanted = want_h8300h;
+      wanted = want_h8300h;
+      switch (TARGET_ARCHITECTURE->mach)
+	{
+	case bfd_mach_h8300s:
+	case bfd_mach_h8300sn:
+	case bfd_mach_h8300sx:
+	case bfd_mach_h8300sxn:
+	  wanted = want_h8300s;
+	}
     }
-#endif
 
   fetch_regs_from_dump (gch, wanted);
 
@@ -2046,15 +2045,18 @@ e7000_wait (ptid_t ptid, struct target_w
 	  wanted_nopc = want_nopc_sh3;
 	}
     }
-#ifdef GDB_TARGET_IS_H8300
   if (TARGET_ARCHITECTURE->arch == bfd_arch_h8300)
     {
-      if (h8300smode)
-	wanted_nopc = want_nopc_h8300s;
-      else
-	wanted_nopc = want_nopc_h8300h;
+      wanted_nopc = want_nopc_h8300h;
+      switch (TARGET_ARCHITECTURE->mach)
+	{
+	case bfd_mach_h8300s:
+	case bfd_mach_h8300sn:
+	case bfd_mach_h8300sx:
+	case bfd_mach_h8300sxn:
+	  wanted_nopc = want_nopc_h8300s;
+	}
     }
-#endif
   fetch_regs_from_dump (gch, wanted_nopc);
 
   /* And supply the extra ones the simulator uses */
diff -upr --strip-trailing-cr gdb+dejagnu-20031114.orig/sim/h8300/compile.c gdb+dejagnu-20031114/sim/h8300/compile.c
--- gdb+dejagnu-20031114.orig/sim/h8300/compile.c	2003-10-17 18:15:56.000000000 +0530
+++ gdb+dejagnu-20031114/sim/h8300/compile.c	2003-11-27 15:20:43.000000000 +0530
@@ -4930,6 +4930,8 @@ set_h8300h (unsigned long machine)
      This function being replaced by a sim_open:ARGV configuration
      option.  */
 
+  h8300hmode = h8300smode = h8300sxmode = h8300_normal_mode = 0;
+
   if (machine == bfd_mach_h8300sx || machine == bfd_mach_h8300sxn)
     h8300sxmode = 1;
 


> -----Original Message-----
> From: Andrew Cagney [mailto:ac131313@redhat.com]
> Sent: Friday, November 14, 2003 8:19 PM
> To: Dhananjay R. Deshpande
> Cc: gdb-patches@sources.redhat.com
> Subject: Re: H8300 Patch - Fix GDB crash problem when object file of
> different H8 cpu is loaded
> 
> 
> > Hi,
> > 
> > Currently if you are debugging one object and load another 
> object of different 
> > H8 CPU then the GDB crashes in h8300_register_name() saying 
> "invalid register number". This is because in gdbarch_init we 
> are returning existing gdbarch but 
> > the globals h8300hmode, h8300smode, etc. are not set again 
> corresponding to 
> > newly loaded object.
> > 
> > The patch below initializes these globals before returning 
> existing gdbarch.
> 
> Unfortunatly this isn't the right way to go.  Because it is 
> now possible 
> for GDB can have more than one active architecture, code that rely on 
> global state can no longer work.  The globals:
> 
>  > +      h8300_normal_mode = 0;
>  > +      h8300sxmode = 0;
>  > +      h8300smode = 0;
>  > +      h8300hmode = 0;
> 
> will need to be eliminated.  Looking at your patch it doesn't 
> look too 
> bad.  Given h8300smode, I'd replace it with a function vis:
> 
> int
> h8300smode (struct gdbarch *gdbarch)
> {
>    return gdbarch_bfd_arch_info (current_gdbarch)->mach == 
> bfd_mach_h8300s
> }
> 
> and called:
> 	
> 	if (h8300smode (current_gdbarch))
> 
> Andrew
> 
> > Changelog - 
> > 
> > 2003-11-14  Dhananjay Deshpande <dhananjayd@kpitcummins.com>
> >         * gdb/h8300-tdep.c (h8300_gdbarch_init): Set 
> globals before returning existing gdbarch
> > 
> > 
> ==============================================================
> ===================
> > --- gdb/h8300-tdep.c.old	2003-11-12 13:51:36.000000000 +0530
> > +++ gdb/h8300-tdep.c	2003-11-14 11:08:29.000000000 +0530
> > @@ -1176,6 +1176,53 @@ h8300_gdbarch_init (struct gdbarch_info 
> >    struct gdbarch_tdep *tdep = NULL;
> >    struct gdbarch *gdbarch;
> >  
> > +  /* Set globals */
> > +  switch (info.bfd_arch_info->mach)
> > +    {
> > +    case bfd_mach_h8300:
> > +      h8300_normal_mode = 0;
> > +      h8300sxmode = 0;
> > +      h8300smode = 0;
> > +      h8300hmode = 0;
> > +      break;
> > +    case bfd_mach_h8300h:
> > +      h8300_normal_mode = 0;
> > +      h8300sxmode = 0;
> > +      h8300smode = 0;
> > +      h8300hmode = 1;
> > +      break;
> > +    case bfd_mach_h8300hn:
> > +      h8300_normal_mode = 1;
> > +      h8300sxmode = 0;
> > +      h8300smode = 0;
> > +      h8300hmode = 1;
> > +      break;
> > +    case bfd_mach_h8300s:
> > +      h8300_normal_mode = 0;
> > +      h8300sxmode = 0;
> > +      h8300smode = 1;
> > +      h8300hmode = 1;
> > +      break;
> > +    case bfd_mach_h8300sn:
> > +      h8300_normal_mode = 1;
> > +      h8300sxmode = 0;
> > +      h8300smode = 1;
> > +      h8300hmode = 1;
> > +      break;
> > +    case bfd_mach_h8300sx:
> > +      h8300_normal_mode = 0;
> > +      h8300sxmode = 1;
> > +      h8300smode = 1;
> > +      h8300hmode = 1;
> > +      break;
> > +    case bfd_mach_h8300sxn:
> > +      h8300_normal_mode = 1;
> > +      h8300sxmode = 1;
> > +      h8300smode = 1;
> > +      h8300hmode = 1;
> > +      break;
> > +    }
> > +
> >    arches = gdbarch_list_lookup_by_info (arches, &info);
> >    if (arches != NULL)
> >      return arches->gdbarch;
> > @@ -1192,9 +1239,6 @@ h8300_gdbarch_init (struct gdbarch_info 
> >    switch (info.bfd_arch_info->mach)
> >      {
> >      case bfd_mach_h8300:
> > -      h8300sxmode = 0;
> > -      h8300smode = 0;
> > -      h8300hmode = 0;
> >        set_gdbarch_num_regs (gdbarch, 13);
> >        set_gdbarch_num_pseudo_regs (gdbarch, 1);
> >        set_gdbarch_ecoff_reg_to_regnum (gdbarch, 
> h8300_dbg_reg_to_regnum);
> > @@ -1210,9 +1254,6 @@ h8300_gdbarch_init (struct gdbarch_info 
> >        break;
> >      case bfd_mach_h8300h:
> >      case bfd_mach_h8300hn:
> > -      h8300sxmode = 0;
> > -      h8300smode = 0;
> > -      h8300hmode = 1;
> >        set_gdbarch_num_regs (gdbarch, 13);
> >        set_gdbarch_num_pseudo_regs (gdbarch, 1);
> >        set_gdbarch_ecoff_reg_to_regnum (gdbarch, 
> h8300_dbg_reg_to_regnum);
> > @@ -1222,13 +1263,11 @@ h8300_gdbarch_init (struct gdbarch_info 
> >        set_gdbarch_register_name (gdbarch, h8300_register_name);
> >        if(info.bfd_arch_info->mach != bfd_mach_h8300hn)
> >          {
> > -          h8300_normal_mode = 0;
> >            set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
> >            set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
> >          }
> >        else
> >          {
> > -          h8300_normal_mode = 1;
> >            set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
> >            set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
> >          }
> > @@ -1238,9 +1277,6 @@ h8300_gdbarch_init (struct gdbarch_info 
> >        break;
> >      case bfd_mach_h8300s:
> >      case bfd_mach_h8300sn:
> > -      h8300sxmode = 0;
> > -      h8300smode = 1;
> > -      h8300hmode = 1;
> >        set_gdbarch_num_regs (gdbarch, 16);
> >        set_gdbarch_num_pseudo_regs (gdbarch, 2);
> >        set_gdbarch_ecoff_reg_to_regnum (gdbarch, 
> h8300s_dbg_reg_to_regnum);
> > @@ -1250,13 +1286,11 @@ h8300_gdbarch_init (struct gdbarch_info 
> >        set_gdbarch_register_name (gdbarch, h8300s_register_name);
> >        if(info.bfd_arch_info->mach != bfd_mach_h8300sn)
> >          {
> > -          h8300_normal_mode = 0;
> >            set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
> >            set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
> >          }
> >        else
> >          {
> > -          h8300_normal_mode = 1;
> >            set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
> >            set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
> >          }
> > @@ -1266,9 +1300,6 @@ h8300_gdbarch_init (struct gdbarch_info 
> >        break;
> >      case bfd_mach_h8300sx:
> >      case bfd_mach_h8300sxn:
> > -      h8300sxmode = 1;
> > -      h8300smode = 1;
> > -      h8300hmode = 1;
> >        set_gdbarch_num_regs (gdbarch, 18);
> >        set_gdbarch_num_pseudo_regs (gdbarch, 2);
> >        set_gdbarch_ecoff_reg_to_regnum (gdbarch, 
> h8300s_dbg_reg_to_regnum);
> > @@ -1278,13 +1309,11 @@ h8300_gdbarch_init (struct gdbarch_info 
> >        set_gdbarch_register_name (gdbarch, h8300sx_register_name);
> >        if(info.bfd_arch_info->mach != bfd_mach_h8300sxn)
> >          {
> > -          h8300_normal_mode = 0;
> >            set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
> >            set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
> >          }
> >        else
> >          {
> > -          h8300_normal_mode = 1;
> >            set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
> >            set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
> >          }
> > 
> ==============================================================
> ===================
> > 
> 
> 
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
  2003-11-14 20:13     ` Michael Snyder
@ 2003-11-14 21:09       ` Andrew Cagney
  0 siblings, 0 replies; 15+ messages in thread
From: Andrew Cagney @ 2003-11-14 21:09 UTC (permalink / raw)
  To: Michael Snyder; +Cc: Andrew Cagney, Dhananjay R. Deshpande, gdb-patches


> On further reflection, Andrew, the sim also needs to be able to
> set these variables.  In fact, they really belong to the sim,
> in as much as that's where they're defined.

Sounds like similar but separate problems - both the sim and gdb need to 
look at their current local architecture.

Andrew



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
  2003-11-14 20:03   ` Michael Snyder
@ 2003-11-14 20:13     ` Michael Snyder
  2003-11-14 21:09       ` Andrew Cagney
  0 siblings, 1 reply; 15+ messages in thread
From: Michael Snyder @ 2003-11-14 20:13 UTC (permalink / raw)
  To: Michael Snyder; +Cc: Andrew Cagney, Dhananjay R. Deshpande, gdb-patches

Michael Snyder wrote:
> Andrew Cagney wrote:

>> Unfortunatly this isn't the right way to go. 

BTW, I'm glad you replied to this -- I was going to just approve it.  ;-)

> The only problem is, these functions would be called from the sim.
> Since the sim doesn't know about struct gdbarch, and since you've
> written them as using the global current_gdbarch anyway, they
> probably should have no argument.

On further reflection, Andrew, the sim also needs to be able to
set these variables.  In fact, they really belong to the sim,
in as much as that's where they're defined.


> 
> Michael
> 
>>
>>> Changelog -
>>> 2003-11-14  Dhananjay Deshpande <dhananjayd@kpitcummins.com>
>>>         * gdb/h8300-tdep.c (h8300_gdbarch_init): Set globals before 
>>> returning existing gdbarch
>>>
>>> ================================================================================= 
>>>
>>> --- gdb/h8300-tdep.c.old    2003-11-12 13:51:36.000000000 +0530
>>> +++ gdb/h8300-tdep.c    2003-11-14 11:08:29.000000000 +0530
>>> @@ -1176,6 +1176,53 @@ h8300_gdbarch_init (struct gdbarch_info    
>>> struct gdbarch_tdep *tdep = NULL;
>>>    struct gdbarch *gdbarch;
>>>  
>>> +  /* Set globals */
>>> +  switch (info.bfd_arch_info->mach)
>>> +    {
>>> +    case bfd_mach_h8300:
>>> +      h8300_normal_mode = 0;
>>> +      h8300sxmode = 0;
>>> +      h8300smode = 0;
>>> +      h8300hmode = 0;
>>> +      break;
>>> +    case bfd_mach_h8300h:
>>> +      h8300_normal_mode = 0;
>>> +      h8300sxmode = 0;
>>> +      h8300smode = 0;
>>> +      h8300hmode = 1;
>>> +      break;
>>> +    case bfd_mach_h8300hn:
>>> +      h8300_normal_mode = 1;
>>> +      h8300sxmode = 0;
>>> +      h8300smode = 0;
>>> +      h8300hmode = 1;
>>> +      break;
>>> +    case bfd_mach_h8300s:
>>> +      h8300_normal_mode = 0;
>>> +      h8300sxmode = 0;
>>> +      h8300smode = 1;
>>> +      h8300hmode = 1;
>>> +      break;
>>> +    case bfd_mach_h8300sn:
>>> +      h8300_normal_mode = 1;
>>> +      h8300sxmode = 0;
>>> +      h8300smode = 1;
>>> +      h8300hmode = 1;
>>> +      break;
>>> +    case bfd_mach_h8300sx:
>>> +      h8300_normal_mode = 0;
>>> +      h8300sxmode = 1;
>>> +      h8300smode = 1;
>>> +      h8300hmode = 1;
>>> +      break;
>>> +    case bfd_mach_h8300sxn:
>>> +      h8300_normal_mode = 1;
>>> +      h8300sxmode = 1;
>>> +      h8300smode = 1;
>>> +      h8300hmode = 1;
>>> +      break;
>>> +    }
>>> +
>>>    arches = gdbarch_list_lookup_by_info (arches, &info);
>>>    if (arches != NULL)
>>>      return arches->gdbarch;
>>> @@ -1192,9 +1239,6 @@ h8300_gdbarch_init (struct gdbarch_info    
>>> switch (info.bfd_arch_info->mach)
>>>      {
>>>      case bfd_mach_h8300:
>>> -      h8300sxmode = 0;
>>> -      h8300smode = 0;
>>> -      h8300hmode = 0;
>>>        set_gdbarch_num_regs (gdbarch, 13);
>>>        set_gdbarch_num_pseudo_regs (gdbarch, 1);
>>>        set_gdbarch_ecoff_reg_to_regnum (gdbarch, 
>>> h8300_dbg_reg_to_regnum);
>>> @@ -1210,9 +1254,6 @@ h8300_gdbarch_init (struct gdbarch_info        
>>> break;
>>>      case bfd_mach_h8300h:
>>>      case bfd_mach_h8300hn:
>>> -      h8300sxmode = 0;
>>> -      h8300smode = 0;
>>> -      h8300hmode = 1;
>>>        set_gdbarch_num_regs (gdbarch, 13);
>>>        set_gdbarch_num_pseudo_regs (gdbarch, 1);
>>>        set_gdbarch_ecoff_reg_to_regnum (gdbarch, 
>>> h8300_dbg_reg_to_regnum);
>>> @@ -1222,13 +1263,11 @@ h8300_gdbarch_init (struct 
>>> gdbarch_info        set_gdbarch_register_name (gdbarch, 
>>> h8300_register_name);
>>>        if(info.bfd_arch_info->mach != bfd_mach_h8300hn)
>>>          {
>>> -          h8300_normal_mode = 0;
>>>            set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>>>            set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>>>          }
>>>        else
>>>          {
>>> -          h8300_normal_mode = 1;
>>>            set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>>>            set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>>>          }
>>> @@ -1238,9 +1277,6 @@ h8300_gdbarch_init (struct gdbarch_info        
>>> break;
>>>      case bfd_mach_h8300s:
>>>      case bfd_mach_h8300sn:
>>> -      h8300sxmode = 0;
>>> -      h8300smode = 1;
>>> -      h8300hmode = 1;
>>>        set_gdbarch_num_regs (gdbarch, 16);
>>>        set_gdbarch_num_pseudo_regs (gdbarch, 2);
>>>        set_gdbarch_ecoff_reg_to_regnum (gdbarch, 
>>> h8300s_dbg_reg_to_regnum);
>>> @@ -1250,13 +1286,11 @@ h8300_gdbarch_init (struct 
>>> gdbarch_info        set_gdbarch_register_name (gdbarch, 
>>> h8300s_register_name);
>>>        if(info.bfd_arch_info->mach != bfd_mach_h8300sn)
>>>          {
>>> -          h8300_normal_mode = 0;
>>>            set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>>>            set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>>>          }
>>>        else
>>>          {
>>> -          h8300_normal_mode = 1;
>>>            set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>>>            set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>>>          }
>>> @@ -1266,9 +1300,6 @@ h8300_gdbarch_init (struct gdbarch_info        
>>> break;
>>>      case bfd_mach_h8300sx:
>>>      case bfd_mach_h8300sxn:
>>> -      h8300sxmode = 1;
>>> -      h8300smode = 1;
>>> -      h8300hmode = 1;
>>>        set_gdbarch_num_regs (gdbarch, 18);
>>>        set_gdbarch_num_pseudo_regs (gdbarch, 2);
>>>        set_gdbarch_ecoff_reg_to_regnum (gdbarch, 
>>> h8300s_dbg_reg_to_regnum);
>>> @@ -1278,13 +1309,11 @@ h8300_gdbarch_init (struct 
>>> gdbarch_info        set_gdbarch_register_name (gdbarch, 
>>> h8300sx_register_name);
>>>        if(info.bfd_arch_info->mach != bfd_mach_h8300sxn)
>>>          {
>>> -          h8300_normal_mode = 0;
>>>            set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>>>            set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>>>          }
>>>        else
>>>          {
>>> -          h8300_normal_mode = 1;
>>>            set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>>>            set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>>>          }
>>> ================================================================================= 
>>>
>>>
>>
>>
>>
> 
> 
> 



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
  2003-11-14 14:49 ` Andrew Cagney
@ 2003-11-14 20:03   ` Michael Snyder
  2003-11-14 20:13     ` Michael Snyder
  0 siblings, 1 reply; 15+ messages in thread
From: Michael Snyder @ 2003-11-14 20:03 UTC (permalink / raw)
  To: Andrew Cagney; +Cc: Dhananjay R. Deshpande, gdb-patches

Andrew Cagney wrote:
>> Hi,
>>
>> Currently if you are debugging one object and load another object of 
>> different H8 CPU then the GDB crashes in h8300_register_name() saying 
>> "invalid register number". This is because in gdbarch_init we are 
>> returning existing gdbarch but the globals h8300hmode, h8300smode, 
>> etc. are not set again corresponding to newly loaded object.
>>
>> The patch below initializes these globals before returning existing 
>> gdbarch.
> 
> 
> Unfortunatly this isn't the right way to go.  Because it is now possible 
> for GDB can have more than one active architecture, code that rely on 
> global state can no longer work.  The globals:
> 
>  > +      h8300_normal_mode = 0;
>  > +      h8300sxmode = 0;
>  > +      h8300smode = 0;
>  > +      h8300hmode = 0;
> 
> will need to be eliminated. 

Would it be appropriate to move them into the gdbarch_tdep struct?

 > Looking at your patch it doesn't look too
> bad.  Given h8300smode, I'd replace it with a function vis:
> 
> int
> h8300smode (struct gdbarch *gdbarch)
> {
>   return gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300s
> }
> 
> and called:
>     
>     if (h8300smode (current_gdbarch))
> 
> Andrew

The only problem is, these functions would be called from the sim.
Since the sim doesn't know about struct gdbarch, and since you've
written them as using the global current_gdbarch anyway, they
probably should have no argument.

Michael

> 
>> Changelog -
>> 2003-11-14  Dhananjay Deshpande <dhananjayd@kpitcummins.com>
>>         * gdb/h8300-tdep.c (h8300_gdbarch_init): Set globals before 
>> returning existing gdbarch
>>
>> ================================================================================= 
>>
>> --- gdb/h8300-tdep.c.old    2003-11-12 13:51:36.000000000 +0530
>> +++ gdb/h8300-tdep.c    2003-11-14 11:08:29.000000000 +0530
>> @@ -1176,6 +1176,53 @@ h8300_gdbarch_init (struct gdbarch_info    
>> struct gdbarch_tdep *tdep = NULL;
>>    struct gdbarch *gdbarch;
>>  
>> +  /* Set globals */
>> +  switch (info.bfd_arch_info->mach)
>> +    {
>> +    case bfd_mach_h8300:
>> +      h8300_normal_mode = 0;
>> +      h8300sxmode = 0;
>> +      h8300smode = 0;
>> +      h8300hmode = 0;
>> +      break;
>> +    case bfd_mach_h8300h:
>> +      h8300_normal_mode = 0;
>> +      h8300sxmode = 0;
>> +      h8300smode = 0;
>> +      h8300hmode = 1;
>> +      break;
>> +    case bfd_mach_h8300hn:
>> +      h8300_normal_mode = 1;
>> +      h8300sxmode = 0;
>> +      h8300smode = 0;
>> +      h8300hmode = 1;
>> +      break;
>> +    case bfd_mach_h8300s:
>> +      h8300_normal_mode = 0;
>> +      h8300sxmode = 0;
>> +      h8300smode = 1;
>> +      h8300hmode = 1;
>> +      break;
>> +    case bfd_mach_h8300sn:
>> +      h8300_normal_mode = 1;
>> +      h8300sxmode = 0;
>> +      h8300smode = 1;
>> +      h8300hmode = 1;
>> +      break;
>> +    case bfd_mach_h8300sx:
>> +      h8300_normal_mode = 0;
>> +      h8300sxmode = 1;
>> +      h8300smode = 1;
>> +      h8300hmode = 1;
>> +      break;
>> +    case bfd_mach_h8300sxn:
>> +      h8300_normal_mode = 1;
>> +      h8300sxmode = 1;
>> +      h8300smode = 1;
>> +      h8300hmode = 1;
>> +      break;
>> +    }
>> +
>>    arches = gdbarch_list_lookup_by_info (arches, &info);
>>    if (arches != NULL)
>>      return arches->gdbarch;
>> @@ -1192,9 +1239,6 @@ h8300_gdbarch_init (struct gdbarch_info    
>> switch (info.bfd_arch_info->mach)
>>      {
>>      case bfd_mach_h8300:
>> -      h8300sxmode = 0;
>> -      h8300smode = 0;
>> -      h8300hmode = 0;
>>        set_gdbarch_num_regs (gdbarch, 13);
>>        set_gdbarch_num_pseudo_regs (gdbarch, 1);
>>        set_gdbarch_ecoff_reg_to_regnum (gdbarch, 
>> h8300_dbg_reg_to_regnum);
>> @@ -1210,9 +1254,6 @@ h8300_gdbarch_init (struct gdbarch_info        
>> break;
>>      case bfd_mach_h8300h:
>>      case bfd_mach_h8300hn:
>> -      h8300sxmode = 0;
>> -      h8300smode = 0;
>> -      h8300hmode = 1;
>>        set_gdbarch_num_regs (gdbarch, 13);
>>        set_gdbarch_num_pseudo_regs (gdbarch, 1);
>>        set_gdbarch_ecoff_reg_to_regnum (gdbarch, 
>> h8300_dbg_reg_to_regnum);
>> @@ -1222,13 +1263,11 @@ h8300_gdbarch_init (struct gdbarch_info        
>> set_gdbarch_register_name (gdbarch, h8300_register_name);
>>        if(info.bfd_arch_info->mach != bfd_mach_h8300hn)
>>          {
>> -          h8300_normal_mode = 0;
>>            set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>>            set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>>          }
>>        else
>>          {
>> -          h8300_normal_mode = 1;
>>            set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>>            set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>>          }
>> @@ -1238,9 +1277,6 @@ h8300_gdbarch_init (struct gdbarch_info        
>> break;
>>      case bfd_mach_h8300s:
>>      case bfd_mach_h8300sn:
>> -      h8300sxmode = 0;
>> -      h8300smode = 1;
>> -      h8300hmode = 1;
>>        set_gdbarch_num_regs (gdbarch, 16);
>>        set_gdbarch_num_pseudo_regs (gdbarch, 2);
>>        set_gdbarch_ecoff_reg_to_regnum (gdbarch, 
>> h8300s_dbg_reg_to_regnum);
>> @@ -1250,13 +1286,11 @@ h8300_gdbarch_init (struct gdbarch_info        
>> set_gdbarch_register_name (gdbarch, h8300s_register_name);
>>        if(info.bfd_arch_info->mach != bfd_mach_h8300sn)
>>          {
>> -          h8300_normal_mode = 0;
>>            set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>>            set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>>          }
>>        else
>>          {
>> -          h8300_normal_mode = 1;
>>            set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>>            set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>>          }
>> @@ -1266,9 +1300,6 @@ h8300_gdbarch_init (struct gdbarch_info        
>> break;
>>      case bfd_mach_h8300sx:
>>      case bfd_mach_h8300sxn:
>> -      h8300sxmode = 1;
>> -      h8300smode = 1;
>> -      h8300hmode = 1;
>>        set_gdbarch_num_regs (gdbarch, 18);
>>        set_gdbarch_num_pseudo_regs (gdbarch, 2);
>>        set_gdbarch_ecoff_reg_to_regnum (gdbarch, 
>> h8300s_dbg_reg_to_regnum);
>> @@ -1278,13 +1309,11 @@ h8300_gdbarch_init (struct gdbarch_info        
>> set_gdbarch_register_name (gdbarch, h8300sx_register_name);
>>        if(info.bfd_arch_info->mach != bfd_mach_h8300sxn)
>>          {
>> -          h8300_normal_mode = 0;
>>            set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>>            set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>>          }
>>        else
>>          {
>> -          h8300_normal_mode = 1;
>>            set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>>            set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>>          }
>> ================================================================================= 
>>
>>
> 
> 
> 



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
  2003-11-14  8:58 Dhananjay R. Deshpande
@ 2003-11-14 14:49 ` Andrew Cagney
  2003-11-14 20:03   ` Michael Snyder
  0 siblings, 1 reply; 15+ messages in thread
From: Andrew Cagney @ 2003-11-14 14:49 UTC (permalink / raw)
  To: Dhananjay R. Deshpande; +Cc: gdb-patches

> Hi,
> 
> Currently if you are debugging one object and load another object of different 
> H8 CPU then the GDB crashes in h8300_register_name() saying "invalid register number". This is because in gdbarch_init we are returning existing gdbarch but 
> the globals h8300hmode, h8300smode, etc. are not set again corresponding to 
> newly loaded object.
> 
> The patch below initializes these globals before returning existing gdbarch.

Unfortunatly this isn't the right way to go.  Because it is now possible 
for GDB can have more than one active architecture, code that rely on 
global state can no longer work.  The globals:

 > +      h8300_normal_mode = 0;
 > +      h8300sxmode = 0;
 > +      h8300smode = 0;
 > +      h8300hmode = 0;

will need to be eliminated.  Looking at your patch it doesn't look too 
bad.  Given h8300smode, I'd replace it with a function vis:

int
h8300smode (struct gdbarch *gdbarch)
{
   return gdbarch_bfd_arch_info (current_gdbarch)->mach == bfd_mach_h8300s
}

and called:
	
	if (h8300smode (current_gdbarch))

Andrew

> Changelog - 
> 
> 2003-11-14  Dhananjay Deshpande <dhananjayd@kpitcummins.com>
>         * gdb/h8300-tdep.c (h8300_gdbarch_init): Set globals before returning existing gdbarch
> 
> =================================================================================
> --- gdb/h8300-tdep.c.old	2003-11-12 13:51:36.000000000 +0530
> +++ gdb/h8300-tdep.c	2003-11-14 11:08:29.000000000 +0530
> @@ -1176,6 +1176,53 @@ h8300_gdbarch_init (struct gdbarch_info 
>    struct gdbarch_tdep *tdep = NULL;
>    struct gdbarch *gdbarch;
>  
> +  /* Set globals */
> +  switch (info.bfd_arch_info->mach)
> +    {
> +    case bfd_mach_h8300:
> +      h8300_normal_mode = 0;
> +      h8300sxmode = 0;
> +      h8300smode = 0;
> +      h8300hmode = 0;
> +      break;
> +    case bfd_mach_h8300h:
> +      h8300_normal_mode = 0;
> +      h8300sxmode = 0;
> +      h8300smode = 0;
> +      h8300hmode = 1;
> +      break;
> +    case bfd_mach_h8300hn:
> +      h8300_normal_mode = 1;
> +      h8300sxmode = 0;
> +      h8300smode = 0;
> +      h8300hmode = 1;
> +      break;
> +    case bfd_mach_h8300s:
> +      h8300_normal_mode = 0;
> +      h8300sxmode = 0;
> +      h8300smode = 1;
> +      h8300hmode = 1;
> +      break;
> +    case bfd_mach_h8300sn:
> +      h8300_normal_mode = 1;
> +      h8300sxmode = 0;
> +      h8300smode = 1;
> +      h8300hmode = 1;
> +      break;
> +    case bfd_mach_h8300sx:
> +      h8300_normal_mode = 0;
> +      h8300sxmode = 1;
> +      h8300smode = 1;
> +      h8300hmode = 1;
> +      break;
> +    case bfd_mach_h8300sxn:
> +      h8300_normal_mode = 1;
> +      h8300sxmode = 1;
> +      h8300smode = 1;
> +      h8300hmode = 1;
> +      break;
> +    }
> +
>    arches = gdbarch_list_lookup_by_info (arches, &info);
>    if (arches != NULL)
>      return arches->gdbarch;
> @@ -1192,9 +1239,6 @@ h8300_gdbarch_init (struct gdbarch_info 
>    switch (info.bfd_arch_info->mach)
>      {
>      case bfd_mach_h8300:
> -      h8300sxmode = 0;
> -      h8300smode = 0;
> -      h8300hmode = 0;
>        set_gdbarch_num_regs (gdbarch, 13);
>        set_gdbarch_num_pseudo_regs (gdbarch, 1);
>        set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
> @@ -1210,9 +1254,6 @@ h8300_gdbarch_init (struct gdbarch_info 
>        break;
>      case bfd_mach_h8300h:
>      case bfd_mach_h8300hn:
> -      h8300sxmode = 0;
> -      h8300smode = 0;
> -      h8300hmode = 1;
>        set_gdbarch_num_regs (gdbarch, 13);
>        set_gdbarch_num_pseudo_regs (gdbarch, 1);
>        set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
> @@ -1222,13 +1263,11 @@ h8300_gdbarch_init (struct gdbarch_info 
>        set_gdbarch_register_name (gdbarch, h8300_register_name);
>        if(info.bfd_arch_info->mach != bfd_mach_h8300hn)
>          {
> -          h8300_normal_mode = 0;
>            set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>            set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>          }
>        else
>          {
> -          h8300_normal_mode = 1;
>            set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>            set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>          }
> @@ -1238,9 +1277,6 @@ h8300_gdbarch_init (struct gdbarch_info 
>        break;
>      case bfd_mach_h8300s:
>      case bfd_mach_h8300sn:
> -      h8300sxmode = 0;
> -      h8300smode = 1;
> -      h8300hmode = 1;
>        set_gdbarch_num_regs (gdbarch, 16);
>        set_gdbarch_num_pseudo_regs (gdbarch, 2);
>        set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
> @@ -1250,13 +1286,11 @@ h8300_gdbarch_init (struct gdbarch_info 
>        set_gdbarch_register_name (gdbarch, h8300s_register_name);
>        if(info.bfd_arch_info->mach != bfd_mach_h8300sn)
>          {
> -          h8300_normal_mode = 0;
>            set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>            set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>          }
>        else
>          {
> -          h8300_normal_mode = 1;
>            set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>            set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>          }
> @@ -1266,9 +1300,6 @@ h8300_gdbarch_init (struct gdbarch_info 
>        break;
>      case bfd_mach_h8300sx:
>      case bfd_mach_h8300sxn:
> -      h8300sxmode = 1;
> -      h8300smode = 1;
> -      h8300hmode = 1;
>        set_gdbarch_num_regs (gdbarch, 18);
>        set_gdbarch_num_pseudo_regs (gdbarch, 2);
>        set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
> @@ -1278,13 +1309,11 @@ h8300_gdbarch_init (struct gdbarch_info 
>        set_gdbarch_register_name (gdbarch, h8300sx_register_name);
>        if(info.bfd_arch_info->mach != bfd_mach_h8300sxn)
>          {
> -          h8300_normal_mode = 0;
>            set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>            set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
>          }
>        else
>          {
> -          h8300_normal_mode = 1;
>            set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>            set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
>          }
> =================================================================================
> 



^ permalink raw reply	[flat|nested] 15+ messages in thread

* H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded
@ 2003-11-14  8:58 Dhananjay R. Deshpande
  2003-11-14 14:49 ` Andrew Cagney
  0 siblings, 1 reply; 15+ messages in thread
From: Dhananjay R. Deshpande @ 2003-11-14  8:58 UTC (permalink / raw)
  To: gdb-patches

Hi,

Currently if you are debugging one object and load another object of different 
H8 CPU then the GDB crashes in h8300_register_name() saying "invalid register number". This is because in gdbarch_init we are returning existing gdbarch but 
the globals h8300hmode, h8300smode, etc. are not set again corresponding to 
newly loaded object.

The patch below initializes these globals before returning existing gdbarch.

Regards,
Dhananjay

Changelog - 

2003-11-14  Dhananjay Deshpande <dhananjayd@kpitcummins.com>
        * gdb/h8300-tdep.c (h8300_gdbarch_init): Set globals before returning existing gdbarch

=================================================================================
--- gdb/h8300-tdep.c.old	2003-11-12 13:51:36.000000000 +0530
+++ gdb/h8300-tdep.c	2003-11-14 11:08:29.000000000 +0530
@@ -1176,6 +1176,53 @@ h8300_gdbarch_init (struct gdbarch_info 
   struct gdbarch_tdep *tdep = NULL;
   struct gdbarch *gdbarch;
 
+  /* Set globals */
+  switch (info.bfd_arch_info->mach)
+    {
+    case bfd_mach_h8300:
+      h8300_normal_mode = 0;
+      h8300sxmode = 0;
+      h8300smode = 0;
+      h8300hmode = 0;
+      break;
+    case bfd_mach_h8300h:
+      h8300_normal_mode = 0;
+      h8300sxmode = 0;
+      h8300smode = 0;
+      h8300hmode = 1;
+      break;
+    case bfd_mach_h8300hn:
+      h8300_normal_mode = 1;
+      h8300sxmode = 0;
+      h8300smode = 0;
+      h8300hmode = 1;
+      break;
+    case bfd_mach_h8300s:
+      h8300_normal_mode = 0;
+      h8300sxmode = 0;
+      h8300smode = 1;
+      h8300hmode = 1;
+      break;
+    case bfd_mach_h8300sn:
+      h8300_normal_mode = 1;
+      h8300sxmode = 0;
+      h8300smode = 1;
+      h8300hmode = 1;
+      break;
+    case bfd_mach_h8300sx:
+      h8300_normal_mode = 0;
+      h8300sxmode = 1;
+      h8300smode = 1;
+      h8300hmode = 1;
+      break;
+    case bfd_mach_h8300sxn:
+      h8300_normal_mode = 1;
+      h8300sxmode = 1;
+      h8300smode = 1;
+      h8300hmode = 1;
+      break;
+    }
+
   arches = gdbarch_list_lookup_by_info (arches, &info);
   if (arches != NULL)
     return arches->gdbarch;
@@ -1192,9 +1239,6 @@ h8300_gdbarch_init (struct gdbarch_info 
   switch (info.bfd_arch_info->mach)
     {
     case bfd_mach_h8300:
-      h8300sxmode = 0;
-      h8300smode = 0;
-      h8300hmode = 0;
       set_gdbarch_num_regs (gdbarch, 13);
       set_gdbarch_num_pseudo_regs (gdbarch, 1);
       set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
@@ -1210,9 +1254,6 @@ h8300_gdbarch_init (struct gdbarch_info 
       break;
     case bfd_mach_h8300h:
     case bfd_mach_h8300hn:
-      h8300sxmode = 0;
-      h8300smode = 0;
-      h8300hmode = 1;
       set_gdbarch_num_regs (gdbarch, 13);
       set_gdbarch_num_pseudo_regs (gdbarch, 1);
       set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300_dbg_reg_to_regnum);
@@ -1222,13 +1263,11 @@ h8300_gdbarch_init (struct gdbarch_info 
       set_gdbarch_register_name (gdbarch, h8300_register_name);
       if(info.bfd_arch_info->mach != bfd_mach_h8300hn)
         {
-          h8300_normal_mode = 0;
           set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
         }
       else
         {
-          h8300_normal_mode = 1;
           set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
         }
@@ -1238,9 +1277,6 @@ h8300_gdbarch_init (struct gdbarch_info 
       break;
     case bfd_mach_h8300s:
     case bfd_mach_h8300sn:
-      h8300sxmode = 0;
-      h8300smode = 1;
-      h8300hmode = 1;
       set_gdbarch_num_regs (gdbarch, 16);
       set_gdbarch_num_pseudo_regs (gdbarch, 2);
       set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
@@ -1250,13 +1286,11 @@ h8300_gdbarch_init (struct gdbarch_info 
       set_gdbarch_register_name (gdbarch, h8300s_register_name);
       if(info.bfd_arch_info->mach != bfd_mach_h8300sn)
         {
-          h8300_normal_mode = 0;
           set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
         }
       else
         {
-          h8300_normal_mode = 1;
           set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
         }
@@ -1266,9 +1300,6 @@ h8300_gdbarch_init (struct gdbarch_info 
       break;
     case bfd_mach_h8300sx:
     case bfd_mach_h8300sxn:
-      h8300sxmode = 1;
-      h8300smode = 1;
-      h8300hmode = 1;
       set_gdbarch_num_regs (gdbarch, 18);
       set_gdbarch_num_pseudo_regs (gdbarch, 2);
       set_gdbarch_ecoff_reg_to_regnum (gdbarch, h8300s_dbg_reg_to_regnum);
@@ -1278,13 +1309,11 @@ h8300_gdbarch_init (struct gdbarch_info 
       set_gdbarch_register_name (gdbarch, h8300sx_register_name);
       if(info.bfd_arch_info->mach != bfd_mach_h8300sxn)
         {
-          h8300_normal_mode = 0;
           set_gdbarch_ptr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 4 * TARGET_CHAR_BIT);
         }
       else
         {
-          h8300_normal_mode = 1;
           set_gdbarch_ptr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
           set_gdbarch_addr_bit (gdbarch, 2 * TARGET_CHAR_BIT);
         }
=================================================================================


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2003-12-17 19:32 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-10  5:06 H8300 Patch - Fix GDB crash problem when object file of different H8 cpu is loaded Dhananjay R. Deshpande
2003-12-10 17:10 ` Andrew Cagney
  -- strict thread matches above, loose matches on Subject: below --
2003-12-17  5:59 Dhananjay R. Deshpande
2003-12-17 19:32 ` Michael Snyder
2003-12-11  6:52 Dhananjay R. Deshpande
2003-12-16 23:56 ` Michael Snyder
2003-12-02 13:18 Dhananjay R. Deshpande
2003-12-03  4:24 ` Andrew Cagney
2003-12-01 12:58 Dhananjay R. Deshpande
2003-12-01 17:26 ` Andrew Cagney
2003-11-14  8:58 Dhananjay R. Deshpande
2003-11-14 14:49 ` Andrew Cagney
2003-11-14 20:03   ` Michael Snyder
2003-11-14 20:13     ` Michael Snyder
2003-11-14 21:09       ` Andrew Cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox