Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
145 user(s) are online (112 user(s) are browsing Forums)

Members: 0
Guests: 145

more...

Headlines

Forum Index


Board index » All Posts (billyfish)




Re: GDB
Just popping in
Just popping in


Sorry I've been away from this for a few days, I should now have a chance to catch up.

Go to top


Re: GDB
Just popping in
Just popping in


kas1e described it well, I'd just add a couple of extra things. With gdb you can set breakpoints at any point in a program which will halt the program at that point so you can inspect variables, etc and can step through the program line by line. It will also allow you to check c variables and even call functions to check their results within gdb itself. It makes development so much easier!

Go to top


Re: GDB
Just popping in
Just popping in


@salass00

I'll dig through the code to find out where the file is opened and let you know tomorrow. Given that the code used was real_fseek in bfdio.c, I'd guess that some printfs to lines 121-124 in that file will show which one was called or checking for where HAVE_FOPEN64 is defined. I can checkout the branch before we fixed it tomorrow and let you know if that's ok.

Go to top


Re: GDB
Just popping in
Just popping in


@kas1e

Great idea on adding the tickets, my memory is rubbish at the best of times so having those to look through is the way forward. I'll have another look at the code tomorrow and we can try and work out how to get the exec part sorted. Does that sound ok to you?

Go to top


Re: GDB
Just popping in
Just popping in


@kas1e


Ah sorry for missing that messag, you were ahead of me in spring the problem as seems to offered be the case 😊

Go to top


Re: GDB
Just popping in
Just popping in


@kas1e

Ah! Thanks for coming to the rescue with -lunix, works perfectly. So I currently have a crash in amigaos_create_inferior () when you run a program within gdb. Going by the debug printouts it is crashing in dos library from this call

debug_data.current_process IDOS->CreateNewProcTags(
            
NP_Seglist,         exec_seglist,
            
NP_FreeSeglist,     FALSE,
//            NP_Child,            TRUE,
            
NP_Name,            exec_file,
            
NP_Cli,             TRUE,
            
NP_Arguments,       args,
            
NP_Input,            IDOS->Input(),
            
NP_CloseInput,      FALSE,
            
NP_Output,          IDOS->Output(),
            
NP_CloseOutput,     FALSE,
            
NP_Error,           IDOS->ErrorOutput(),
            
NP_CloseError,      FALSE,
            (
homedir NP_ProgramDirTAG_IGNORE),homedir,
            
TAG_DONE
        
);



with

exec_seglist 
exec_file  
"/Workspace/helloworld" 
args "" 
homedir "NULL"


when I do a run within gdb on helloworld

Does anyone see anything immediately wrong with that call before I head off to the os autodocs ? exec_seglist being 0 maybe? I haven't used CreateNewProc () before so I'm just guessing

Go to top


Re: GDB
Just popping in
Just popping in


@salass00

I'll try and see if I can extract the bits that gdb is doing into a separate program and get that to you

Go to top


Re: GDB
Just popping in
Just popping in


@kas1e I've submitted a pull request, see if it works for you. I'm getting weird issue that https://github.com/kas1e/gdb/tree/81af ... 013839d99f854762f33b2c74c allows me to do

file helloworld


and I get the illegal seeks

but all builds from https://github.com/kas1e/gdb/tree/b880 ... 6e85518997b5be86053dce255 onwards give me requester asking for

/usr/local/lib/debugWorkspace:
/usr/local/share/gdb/auto-loadWorkspace:


workspace: being the partition with helloworld on. The bits before workspace: are paths defined by bfd so at least I can see where they come from

The only thing changed between those two revisions are the "o64" undefs, etc.

Does it all work for you? hopefully it's some stupid setting on my system.

Go to top


Re: GDB
Just popping in
Just popping in


@kas1e

I've replaced BREAKPOINT_FROM_PC, REGISTER_NAME and GDB_SIGNAL_to_name and altered the breakpoint function signatures to match the new spec. Just need to do some testing then I'll do another pull request.

Go to top


Re: GDB
Just popping in
Just popping in


@sTix

You're very right!

Go to top


Re: GDB
Just popping in
Just popping in


@kas1e

Quote:

Are you sure about PC_REGNUM to be just 3?


Ack sorry, that was a total mistake! 😳 Yeah that's definitely wrong, I meant to go back and fix that and forgot to do that last night.

I'll carry on working on that file and make another pull request later. The signatures for the functions to add and remove breakpoints have changed quite a bit so that's the next thing that I'll update.


Edited by billyfish on 2021/2/24 9:52:52
Go to top


Re: GDB
Just popping in
Just popping in


@kas1e

Cheers Roman, great work again. current_regcache looks like an easy fix it's just setting it from get_current_regcache (). I'm working my way through that and the warnings for amigaos-nat.c and will make a pull request for you when I'm done.

BREAKPOINT_FROM_PC (), amigaos_find_lib () and amigaos_add_lib () are currently undefined, are they defined in the 6.3 branch anywhere?


Edited by billyfish on 2021/2/23 23:50:07
Go to top


Re: GDB
Just popping in
Just popping in


@kas1e

Yup, that looks likely. From this gdb code, it should be really easy to create a small test program to show the problem.

Go to top


Re: GDB
Just popping in
Just popping in


Ok so after a few debugging printf () calls, the failing function is

fseeko64 ()

int
real_fseek 
(FILE *filefile_ptr offsetint whence)
{
#if defined (HAVE_FSEEKO64)
printf ("using fseeko64\n");
    return 
fseeko64 (fileoffsetwhence);
#elif defined (HAVE_FSEEKO)
    
printf ("using fseeko\n");
  return 
fseeko (fileoffsetwhence);
#else
  
printf ("using fseek\n");
  return 
fseek (fileoffsetwhence);
#endif
}


from bfd/bfdio.c:57


(gdbfile helloworld
file helloworld
0 calling bfd seek with Workspace
:/helloworld with pos 0 (8) and direction 0 (4)
bfd_seek called with Workspace:/helloworld with pos 0 (8) and direction 0 (4)
bfd_seek called with Workspace:/helloworld with pos 0 (8) and direction 0 (4)
cache_bseek f not null with Workspace:/helloworld with pos 12060 (8) and direction 0 (4)
using fseeko64
real_fseek returned 
-1 with Workspac:/helloworld with pos 12060 (8) and direction 0 (4)
1seeking Workspace:/helloworld with pos 12060 and direction 0 has result 89
4
seeking Workspace:/helloworld has error 29
returning Workspace
:/helloworld 89
"Workspace:/helloworld"not in executable formatIllegal seek
(gdb)



Reverting to the standard c versions by adding


#ifdef __amigaos4__
#undef HAVE_FSEEKO64
#undef HAVE_FSEEKO
#undef HAVE_FTELLO64
#undef HAVE_FTELLO
#undef HAVE_FOPEN64
#endif


to bfdio.c, we get

4.Workspace:> gdb-newlib
GNU gdb 
(GDB7.5.1
Copyright 
(C2012 Free Software FoundationInc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free softwareyou are free to change and redistribute it.
There is NO WARRANTYto the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "ppc-amigaos".
For 
bug reporting instructionsplease see:
<
http://www.gnu.org/software/gdb/bugs/>.
(gdbfile helloworld
file helloworld
0 calling bfd seek with Workspace
:/helloworld with pos 0 (8) and direction 0 (4)
bfd_seek called with Workspace:/helloworld with pos 0 (8) and direction 0 (4)
bfd_seek called with Workspace:/helloworld with pos 0 (8) and direction 0 (4)
cache_bseek f not null with Workspace:/helloworld with pos 12060 (8) and direction 0 (4)
using fseek
real_fseek returned 0 with Workspace
:/helloworld with pos 12060 (8) and direction 0 (4)
1seeking Workspace:/helloworld with pos 12060 and direction 0 has result 88
4
seeking Workspace:/helloworld has error 2
returning Workspace
:/helloworld 88
"Workspace:/helloworld"not in executable formatNo such file or directory
(gdb)



Which is a slight improvement and hopefully by setting

HAVE_FSEEKO64
HAVE_FSEEKO
HAVE_FTELLO64
HAVE_FTELLO
HAVE_FOPEN64

etc., correctly across the entire project we may be getting there as I'm hoping the later failure is due to other parts of the io code still using the "o64" function calls.


Go to top


Re: GDB
Just popping in
Just popping in


@salass00


Ah yup 64 bit! So the debug print is now

(gdbfile helloworld
file helloworld
0 calling bfd seek with Workspace
:/helloworld with pos 0 (8) and direction 0 (4)
bfd_seek called with Workspace:/helloworld with pos 0 (8) and direction 0 (4)
BFDBFD (GNU Binutils2.22.52.20120718 assertion fail ../../bfd/elf.c:241
bfd_seek called with Workspace
:/helloworld with pos 0 (8) and direction 0 (4)
1seeking Workspace:/helloworld with pos 12060 and direction 0 has result -1
4
seeking Workspace:/helloworld has error 29
returning Workspace
:/helloworld : -1
"Workspace:/helloworld"not in executable formatIllegal seek
(gdb)


The numbers in the brackets after the pos and direction are the sizeof values to make sure I don't get caught out with that again

So it's calculated the right position to scroll to for my executable but the subseqeunt seek to this position fails


Edited by billyfish on 2021/2/23 16:52:57
Edited by billyfish on 2021/2/23 17:11:45
Go to top


Re: GDB
Just popping in
Just popping in


OK so I added this at format.c line 206

printf ("0 calling bfd seek with %s with pos %d and direction %d\n"abfd -> filename, (file_ptr0SEEK_SET);


and

int
bfd_seek 
(bfd *abfdfile_ptr positionint direction)
{
  
int result;
  
file_ptr file_position;
  
/* For the time being, a BFD may not seek to it's end.  The problem
     is that we don't easily have a way to recognize the end of an
     element in an archive.  */

  
printf ("bfd_seek called with %s with pos %d and direction %d\n"abfd -> filenamepositiondirection);


  
BFD_ASSERT (direction == SEEK_SET || direction == SEEK_CUR);

  if (
direction == SEEK_CUR && position == 0)
          return 
0;

  if (
abfd->format != bfd_archive && abfd->my_archive == 0)
    {
      if (
direction == SEEK_SET && (bfd_vmaposition == abfd->where)
              return 
0;
    }
  else
    {
      
/* We need something smarter to optimize access to archives.
     Currently, anything inside an archive is read via the file
     handle for the archive.  Which means that a bfd_seek on one
     component affects the `current position' in the archive, as
     well as in any other component.

     It might be sufficient to put a spike through the cache
     abstraction, and look to the archive for the file position,
     but I think we should try for something cleaner.

     In the meantime, no optimization for archives.  */
    
}

  
file_position position;
  if (
direction == SEEK_SET)
    {
      
bfd *parent_bfd abfd;

      while (
parent_bfd->my_archive != NULL)
        {
          
file_position += parent_bfd->origin;
          
parent_bfd parent_bfd->my_archive;
        }
    }

  if (
abfd->iovec)
      {
          
result abfd->iovec->bseek (abfdfile_positiondirection);
          
printf ("1: seeking %s with pos %d and direction %d has result %d\n"abfd -> filenamefile_positiondirectionresult);
      }
  else
      {
            
printf ("2: iovec for %s is null\n"abfd -> filename);
          
result = -1;
      }

  if (
result != 0)
    {
      
int hold_errno errno;

      
/* Force redetermination of `where' field.  */
      
bfd_tell (abfd);

      
/* An EINVAL error probably means that the file offset was
         absurd.  */
      
if (hold_errno == EINVAL)
          {
              
printf ("3: seeking %s EINVAL\n"abfd -> filename);

              
bfd_set_error (bfd_error_file_truncated);
          }
      else
          {
              
bfd_set_error (bfd_error_system_call);
              
errno hold_errno;
              
printf ("4: seeking %s has error %d\n"abfd -> filenamehold_errno);

          }
    }
  else
    {
      
/* Adjust `where' field.  */
      
if (direction == SEEK_SET)
          {
              
printf ("5: seeking %s\n"abfd -> filename);

              
abfd->where position;
          }
      else
          {
              
printf ("6: seeking %s\n"abfd -> filename);
              
abfd->where += position;
          }
    }

    
printf ("returning %s : %d\n"abfd -> filenameresult);

  return 
result;
}


and got the following output:


0 calling bfd seek with Workspace:/helloworld with pos 0 and  direction 0
bfd seek called with Workspace
:/helloworld with pos 0 and  direction 0
BFD
BFD (GNU Binutils2.22.52.20120718 assertion fail ../../bfd/elf.c:241
bfd_seek called with Workspace
:/helloworld with pos 0 and direction 12060
1
seeking Workspace:/helloworld with pos 0 and direction 12060 has result 0
4
seeking Workspace:/helloworld has error 29
returning Worksapce
:/helloworld : -1
"Workspace:/helloworld"not in executable formatillegal seek


So the direction then being 12060 seems like where things go very wrong!

Unless some weird redefining is going on, direction should be 0, 1 or 2 for SEEK_SET, SEEK_CUR and SEEK_END. Even the GNU extensions only add values for 3 and 4. So somewhere direction is getting set strangely.



Go to top


Re: GDB
Just popping in
Just popping in


@kas1e


Quote:

It adds -let and -lunix not at the end of linking line as expected, but at the beginning, before "-o gdb", so it didn't taken into account :(


make LOADLIBES="$LOADLIBES -lunix -lnet"


will do it.

Also we can use EXEEXT flag at the build stage and it will automatically put that at the end of the gdb program name e.g.

make LOADLIBES="$LOADLIBES -lunix -lnet" EXEEXT="-clib2"


will end up with an executeable called gdb-clib2

Go to top


Re: GDB
Just popping in
Just popping in


@kas1e

Awesome! Yup it's even better without the extra flag, one less thing to remember!

Go to top


Re: GDB
Just popping in
Just popping in


@kas1e

Quote:

Just need to understand how to deal with that adding of undefs to alloca/process/malloc without patch , but from configure line (so to not have needs to patch things after configuring, and less steps in build process)


Totally agree. We could have blocks like

#ifdef __amigaos4__
#ifdef CLIB2
<blah>
#else /* newlib */
<blah>
#endif


what do you think?

in inflow.c that block at line 45 is what causes the problem, when building with clib2

so instead of

#ifdef __amigaos4__
#undef HAVE_TERMIOS
#define HAVE_TERMIO 1
#endif


we could have

#ifdef __amigaos4__

#ifdef CLIB2 
  #undef HAVE_TERMIO
#else
  #undef HAVE_TERMIOS
  #define HAVE_TERMIO 1
#endif

#endif



Ideally at the config stage we should just be able to put -DCLIB2=1 in the CFLAGS to switch from newlib to clib2. I did this in the makefiles for simplegit and libgit2 as it'#s a pain in neck/arse to get it building with the two different libs!

Go to top


Re: GDB
Just popping in
Just popping in


config.patch:

--- config.h    2021-02-22 19:00:25.228937154 +0000
+++ config.h-new    2021-02-22 18:59:39.383470770 +0000
@@ -9,+9,@@
 
/* #undef CRAY_STACKSEG_END */
 
 /* Define to 1 if you have the <alloca.h> header file. */
-#define HAVE_ALLOCA_H 1
+/*#define HAVE_ALLOCA_H 1 */
+#undef HAVE_ALLOCA_H 
 
 /* Define to 1 if you have the `asprintf' function. */
 #define HAVE_ASPRINTF 1
@@ -141,+142,@@
 
/* #undef HAVE_MACHINE_HAL_SYSINFO_H */
 
 /* Define to 1 if you have the <malloc.h> header file. */
-#define HAVE_MALLOC_H 1
+/* #define HAVE_MALLOC_H 1 */
+#undef HAVE_MALLOC_H 
 
 /* Define to 1 if you have the `memchr' function. */
 #define HAVE_MEMCHR 1
@@ -174,+176,@@
 
/* #undef HAVE_ON_EXIT */
 
 /* Define to 1 if you have the <process.h> header file. */
-#define HAVE_PROCESS_H 1
+/* #define HAVE_PROCESS_H 1 */
+#undef HAVE_PROCESS_H
 
 /* Define to 1 if you have the `psignal' function. */
 /* #undef HAVE_PSIGNAL */
@@ -297,+300,@@
 
/* #undef HAVE_SYS_ERRLIST */
 
 /* Define to 1 if you have the <sys/file.h> header file. */
-#define HAVE_SYS_FILE_H 1
+/* #define HAVE_SYS_FILE_H 1 */
+#undef HAVE_SYS_FILE_H
 
 /* Define to 1 if you have the <sys/mman.h> header file. */
 /* #undef HAVE_SYS_MMAN_H */
@@ -306,+310,@@
 
/* #undef HAVE_SYS_NERR */
 
 /* Define to 1 if you have the <sys/param.h> header file. */
-#define HAVE_SYS_PARAM_H 1
+/* #define HAVE_SYS_PARAM_H 1 */
+#undef HAVE_SYS_PARAM_H
 
 /* Define to 1 if you have the <sys/prctl.h> header file. */
 /* #undef HAVE_SYS_PRCTL_H */

Go to top



TopTop
« 1 2 (3) 4 5 6 ... 9 »




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project