Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
48 user(s) are online (40 user(s) are browsing Forums)

Members: 1
Guests: 47

emeck, more...

Support us!

Headlines

 
  Register To Post  

« 1 ... 3 4 5 (6) 7 8 9 10 »
Re: GDB
Home away from home
Home away from home


See User information
@Billifish

I checked morphos-nat from gdb 8.x, and just follow the way how they do it. That what i do:

static void
amigaos_create_inferior 
(struct target_ops *opschar *exec_filechar *argschar **envint from_tty)
{
    
char *io_desc;
    
ptid_t ptid;
    
pid_t pid;
    
struct inferior *inf;


    
FUNC;

....
blablaba....

        
IDebug->AddDebugHook((struct Task *)debug_data.current_process, &debug_hook);

    
//inferior_ptid = pid_to_ptid ((int)debug_data.current_process);
    //dprintf("inferior_ptid=%p\n",inferior_ptid);

    
pid = (int)debug_data.current_process;
    
inferior_ptid pid_to_ptid(pid);
    
inf current_inferior();
    
inferior_appeared(infpid);
    
add_thread(inferior_ptid);
    
init_wait_for_inferior ();



    
/* FIXME: This is from the gdb source: You should call clear_proceed_status before calling proceed.  */
    
proceed ((CORE_ADDR) -1GDB_SIGNAL_00);
    
inferior_created TRUE;

    
FUNCX;
}


By this, we pass these issues in target.c/inferior.c, but then crashes later, but i can see that output almost the same as with 6.3a:

Quote:

Breakpoint 1 at 0x10004d4: file test.c, line 1.
(gdb) r
r
Starting program: /Work/aa/test
[New process 1651110656]
target_thread_architecture (process 1651110656) = 0x62295ff8 [powerpc:common]
target_fetch_registers (pc) = 00000000 0x0 0
target_memory_map ()
subtask:target_xfer_partial (2, (null), 0x62290518, 0x0, 0x7fd49460, 4) = 4, bytes = 3d 20 62 3c
subtask:target_xfer_partial (2, (null), 0x0, 0x62579da0, 0x7fd49460, 4) = 4, bytes =
7d 82 10 08
target_insert_breakpoint (0x010004d4, xxx) = 0
target_terminal_inferior ()
target_resume (-1, continue, 0)
target_wait (-1, status) = 1651110656, status->kind = stopped, signal = SIGBUS
target_thread_architecture (process 1651110656) = 0x62295ff8 [powerpc:common]
target_fetch_registers (pc) = 023aecf0 0x23aecf0 37416176
target_stopped_by_watchpoint () = 0
target_terminal_ours_for_output ()

Program received signal SIGBUS, Bus error.
subtask:target_xfer_partial (2, (null), 0x0, 0x62290518, 0x7fd49460, 4) = 4, bytes = 3d 20 62 3c
target_remove_breakpoint (0x010004d4, xxx) = 0
target_terminal_ours ()
0x023aecf0 in ?? ()
target_create_inferior (/Work/aa/test, , xxx, 1)
target_terminal_ours ()
target_get_section_table ()
subtask:target_xfer_partial (10, target.xml, 0x62297ca0, 0x0, 0x0, 4095) = -1
target_get_section_table ()
subtask:target_xfer_partial (11, (null), 0x62297ca0, 0x0, 0x0, 4095) = -1
...crash...


See, on x5k it recieve the same "Program received signal SIGBUS, Bus error." as it was with 6.3a, and pass the same stages, just then crashes in amigaos_xfer_memory().

Will check how it on pegasos2 now.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: GDB
Just popping in
Just popping in


See User information
@kas1e

Yeah looking at the Windows nat for instance, it didn't have to explicitly add the inferior, I may try debugging that to see how it deals with setting up its inferior.

add_inferior_with_spaces () is basically a wrapper around add_inferior (). I've been delving into the gdb internals manual at https://sourceware.org/gdb/wiki/Internals so see if that helps.

You're right in that currently it feels like trying to tweak the existing code and I'm not sure if we're adding the code in the right place for instance with this inferior stuff.

amigaos_create_inferior() creates the inferior absolutely fine, the issue is that the call to find_inferior_pid () at target.c:3249 returns NULL. The code for that is in inferior.c:

struct inferior *
find_inferior_pid (int pid)
{
  
struct inferior *inf;

  
/* Looking for inferior pid == 0 is always wrong, and indicative of
     a bug somewhere else.  There may be more than one with pid == 0,
     for instance.  */
  
gdb_assert (pid != 0);

  for (
inf inferior_listinfinf inf->next)
    if (
inf->pid == pid)
      return 
inf;

  return 
NULL;
}


where inferior_list is a list of all the current inferiors and our amiga one isn't on there.

In inferior.c the api for adding inferiors to this list are

add_inferior ()
add_inferior_with_spaces ()
add_inferior_silent ()


If we use add_inferior () which is essentially add_inferior_silent () with a log message, then at target.c:3251 we fail due to inf -> aspace being NULL

if (inf == NULL || inf->aspace == NULL)






Go to top
Re: GDB
Just popping in
Just popping in


See User information
@kas1e

Could you send me the morphos-nat.c file? I take that their gdb works yeah?

I've also discovered that alfkil's spotless is on github which may be a way to go as at least the codebase is amiga and simpler!

Go to top
Re: GDB
Home away from home
Home away from home


See User information
@billywish
I also edited my previous post, check plz for code and output. See how i pass inverior_not_added / target.c issues : comment out those 2:

Quote:

//inferior_ptid = pid_to_ptid ((int)debug_data.current_process);
//dprintf("inferior_ptid=%pn",inferior_ptid);


And instead:

Quote:

at top of fucntion:
ptid_t ptid;
pid_t pid;
struct inferior *inf;

and instead those 2 commented lines:


pid = (int)debug_data.current_process;
inferior_ptid = pid_to_ptid(pid);
inf = current_inferior();
inferior_appeared(inf, pid);
add_thread(inferior_ptid);
init_wait_for_inferior ();


Quote:

Could you send me the morphos-nat.c file? I take that their gdb works yeah?


Yeah, it works of course, there is:

http://kas1e.mikendezign.com/aos4/gdb/morphos-nat.c
http://kas1e.mikendezign.com/aos4/gdb/morphos-nat.h
http://kas1e.mikendezign.com/aos4/gdb/morphos-tdep.c
http://kas1e.mikendezign.com/aos4/gdb/morphos-tdep.h


My bet we need to just write amigaos-nat from scratch now. Just function by function. So we will then understand everything. Firstly create_inferior, then one fetching registers, etc, etc. That will be easier than tweaking old stuff.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: GDB
Home away from home
Home away from home


See User information
@billifish
Tried on pegasos2 version with my changes in create_inferior : there i come to the point when it recieve Trace/breakpoint trap (exactly the place where X5000 fails with Program received signal SIGBUS, Bus error., so it mean that in amigaos-nat.c, "trap" signal is not recieved on x5k, at least we know now what it SIGBUSes).

Then on pegasos2 it then remove breakpoint, and tried to "Target_create_inferior() again, and then crashes after target_get_section_Table().

But so far alsmost going till end. So my changes in amigaos_create_inferior() seems more or less correct

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: GDB
Just popping in
Just popping in


See User information
@kas1e

Quote:

My bet we need to just write amigaos-nat from scratch now. Just function by function. So we will then understand everything. Firstly create_inferior, then one fetching registers, etc, etc. That will be easier than tweaking old stuff.


I agree, I think the reason we're hitting issues like this are because we're using code that used the previous GDB API and we're better off adpating to the new API instead. we've got this source plus the morphos one (thanks for that!), and the code for spotless so we have enough examples so let's do each function in turn for the new API.

Go to top
Re: GDB
Home away from home
Home away from home


See User information
@billyfish
Quote:

I agree, I think the reason we're hitting issues like this are because we're using code that used the previous GDB API and we're better off adpating to the new API instead. we've got this source plus the morphos one (thanks for that!), and the code for spotless so we have enough examples so let's do each function in turn for the new API.


So, let's start just by creating empty list stubs based on let's say rs6000.c and then adding function one by one in the way they need it. We even not need any debug hooks now, etc, just start from basics : inferior, etc,etc.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: GDB
Just popping in
Just popping in


See User information
@kas1e

Ok I'm now on it, expect a pull request in the next few hours

Go to top
Re: GDB
Just popping in
Just popping in


See User information
@kas1e

Here is a stripped back init_amigaos_ops (). we may have a lot to fill in! But this way we know that there won't be any uninitialised values in amigaos_ops. I'm expecting that quite a lot of them will be trivial no-op functions. There's more info at [link]https://www.embecosm.com/appnotes/ean3/embecosm-howto-gdb-porting-ean3-issue-2.html#sec_target_ops[/link]


/* Native-dependent code for AmigaOS on PowerPC
   for GDB, the GNU debugger.

   Copyright 2000, 2001, 2002 Free Software Foundation, Inc.

   This file is part of GDB.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.  */

#include "defs.h"
#include "gdbcore.h"
#include "inferior.h"
#include "regcache.h"
#include "value.h"
#include "gdb_string.h"
#include "elf/mips.h"
#include "symtab.h"
#include "symfile.h"
#include "objfiles.h"
#include "buildsym.h"
#include "ppc-tdep.h"
#include "stabsread.h"
#include "gdb-stabs.h"
#include "gdbthread.h"
#include "command.h"
#include "libbfd.h"

#undef HAVE_DLFCN_H
#ifdef HAVE_DLFCN_H
#include "solib-amigaos.h"
#endif

#include <exec/execbase.h>
#include <exec/tasks.h>

#if !defined(NDEBUG)
#define FUNC  IExec->DebugPrintF("\033[37m<%s>\033[39m\n", __PRETTY_FUNCTION__);
#define FUNCX IExec->DebugPrintF("\033[37m</%s>\033[39m\n", __PRETTY_FUNCTION__);
#define dprintf(format...) {IExec->Forbid();IExec->DebugPrintF("%s: ",IExec->FindTask(NULL)->tc_Node.ln_Name);IExec->DebugPrintF(format);IExec->Permit();}
//fprintf_unfiltered(gdb_stderr, ## format); 
#else
#define dprintf(format...)
#define FUNC
#define FUNCX
#endif

#define __USE_BASETYPE__
#include <sys/time.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/elf.h>

#include <exec/exec.h>
#include <exec/exectags.h>
#include <exec/ports.h>
#include <exec/interrupts.h>

#include <dos/dos.h>
#include <dos/dostags.h>
#include <dos/dosextens.h>

#include <strings.h>

#define    MSR_TRACE_ENABLE           0x00000400
#define    EXC_FPE                    0x00100000
#define    EXC_ILLEGAL                0x00080000
#define    EXC_PRIV                   0x00040000
#define    EXC_TRAP                   0x00020000
#define    MAX_DEBUG_MESSAGES         20

#define    TASK_TERMINATED            0x00000001
#define    TASK_ATTACHED              0x00000002
#define    TASK_INTERRUPTED           0x00000004
#define       TASK_OPENLIB               0x00000008
#define       TASK_CLOSELIB              0x00000010

extern struct ExecBase *SysBase;

static 
struct target_ops amigaos_ops;

struct DebugIFace *IDebug 0;
struct Library *ElfBase 0;
struct ElfIFace *IElf 0;
struct MMUIFace *IMMU 0;




/*
 * STATIC FUNCTION DECLARATIONS
 */

/** Called from init.c */
static void init_amigaos_ops (void);



/*
 * STATIC FUNCTION DEFINITIONS
 */

static void init_amigaos_ops (void)
{
    
/*
     * start by clearing all entries so we should get a NULL pointer
     * if we try to access anything that hasn't been set. So
     * in case an edit below removes a function pointer value, we'll
     * get a NULL pointer exception rather than accesing a junk value
     * in memory.
     */
    
memset (&amigaos_opssizeof (struct target_ops), 0);

    
/* To the target under this one.  */
    
amigaos_ops.beneath NULL;

    
/* Name this target type */
    
amigaos_ops.to_shortname "subtask";

    
/* Name for printing */
    
amigaos_ops.to_longname "Debug an Amiga process";

    
/*
     * Documentation.  Does not include trailing newline, and starts
     * with a one-line description (probably similar to to_longname).
     */
    
amigaos_ops.to_doc "Debug a Task/Process running on AmigaOS 4\n"
            "Use \"
target subtask <process_id>\" to attach";

    
/* Per-target scratch pad.  */
    
amigaos_ops.to_data NULL;

    
/* The open routine takes the rest of the parameters from the
         command, and (if successful) pushes a new target onto the
         stack.  Targets should supply this routine, if only to provide
         an error message.  */
    
amigaos_ops.to_open NULL;

    
/* Old targets with a static target vector provide "to_close".
         New re-entrant targets provide "to_xclose" and that is expected
         to xfree everything (including the "struct target_ops").  */
    
amigaos_ops.to_xclose NULL;
    
amigaos_ops.to_close NULL;
    
amigaos_ops.to_attach NULL;
    
amigaos_ops.to_post_attach NULL;
    
amigaos_ops.to_detach NULL;
    
amigaos_ops.to_disconnect NULL;
    
amigaos_ops.to_resume NULL;
    
amigaos_ops.to_wait NULL;
    
amigaos_ops.to_fetch_registers NULL;
    
amigaos_ops.to_store_registers NULL;
    
amigaos_ops.to_prepare_to_store NULL;

    
/* Transfer LEN bytes of memory between GDB address MYADDR and
         target address MEMADDR.  If WRITE, transfer them to the target, else
         transfer them from the target.  TARGET is the target from which we
         get this function.

         Return value, N, is one of the following:

         0 means that we can't handle this.  If errno has been set, it is the
         error which prevented us from doing it (FIXME: What about bfd_error?).

         positive (call it N) means that we have transferred N bytes
         starting at MEMADDR.  We might be able to handle more bytes
         beyond this length, but no promises.

         negative (call its absolute value N) means that we cannot
         transfer right at MEMADDR, but we could transfer at least
         something at MEMADDR + N.

         NOTE: cagney/2004-10-01: This has been entirely superseeded by
         to_xfer_partial and inferior inheritance.  */
    
amigaos_ops.deprecated_xfer_memory NULL;

    
amigaos_ops.to_files_info NULL;
    
amigaos_ops.to_insert_breakpoint NULL;
    
amigaos_ops.to_remove_breakpoint NULL;
    
amigaos_ops.to_can_use_hw_breakpoint NULL;
    
amigaos_ops.to_ranged_break_num_registers NULL;
    
amigaos_ops.to_insert_hw_breakpoint NULL;
    
amigaos_ops.to_remove_hw_breakpoint NULL;

    
/* Documentation of what the two routines below are expected to do is
         provided with the corresponding target_* macros.  */
    
amigaos_ops.to_remove_watchpoint NULL;
    
amigaos_ops.to_insert_watchpoint NULL;

    
amigaos_ops.to_insert_mask_watchpoint NULL;

    
amigaos_ops.to_remove_mask_watchpoint NULL;

    
amigaos_ops.to_stopped_by_watchpoint NULL;
    
amigaos_ops.to_have_steppable_watchpoint 0;
    
amigaos_ops.to_have_continuable_watchpoint 0;
    
amigaos_ops.to_stopped_data_address NULL;
    
amigaos_ops.to_watchpoint_addr_within_range NULL;

    
/* Documentation of this routine is provided with the corresponding
         target_* macro.  */
    
amigaos_ops.to_region_ok_for_hw_watchpoint NULL;

    
amigaos_ops.to_can_accel_watchpoint_condition NULL;
    
amigaos_ops.to_masked_watch_num_registers NULL;
    
amigaos_ops.to_terminal_init NULL;
    
amigaos_ops.to_terminal_inferior NULL;
    
amigaos_ops.to_terminal_ours_for_output NULL;
    
amigaos_ops.to_terminal_ours NULL;
    
amigaos_ops.to_terminal_save_ours NULL;
    
amigaos_ops.to_terminal_info NULL;
    
amigaos_ops.to_kill NULL;
    
amigaos_ops.to_load NULL;
    
amigaos_ops.to_create_inferior NULL;
    
amigaos_ops.to_post_startup_inferior NULL;
    
amigaos_ops.to_insert_fork_catchpoint NULL;
    
amigaos_ops.to_remove_fork_catchpoint NULL;
    
amigaos_ops.to_insert_vfork_catchpoint NULL;
    
amigaos_ops.to_remove_vfork_catchpoint NULL;
    
amigaos_ops.to_follow_fork NULL;
    
amigaos_ops.to_insert_exec_catchpoint NULL;
    
amigaos_ops.to_remove_exec_catchpoint NULL;
    
amigaos_ops.to_set_syscall_catchpoint NULL;
    
amigaos_ops.to_has_exited NULL;
    
amigaos_ops.to_mourn_inferior NULL;
    
amigaos_ops.to_can_run NULL;

    
/* Documentation of this routine is provided with the corresponding
         target_* macro.  */
    
amigaos_ops.to_pass_signals NULL;

    
/* Documentation of this routine is provided with the
         corresponding target_* function.  */
    
amigaos_ops.to_program_signals NULL;

    
amigaos_ops.to_thread_alive NULL;
    
amigaos_ops.to_find_new_threads NULL;
    
amigaos_ops.to_pid_to_str NULL;
    
amigaos_ops.to_extra_thread_info NULL;
    
amigaos_ops.to_thread_name NULL;
    
amigaos_ops.to_stop NULL;
    
amigaos_ops.to_rcmd NULL;
    
amigaos_ops.to_pid_to_exec_file NULL;
    
amigaos_ops.to_log_command NULL;
    
amigaos_ops.to_get_section_table NULL;

    
amigaos_ops.to_stratum dummy_stratum;

    
amigaos_ops.to_has_all_memory NULL;
    
amigaos_ops.to_has_memory NULL;
    
amigaos_ops.to_has_stack NULL;
    
amigaos_ops.to_has_registers NULL;
    
amigaos_ops.to_has_execution NULL;

    
/* control thread execution */
    
amigaos_ops.to_has_thread_control 0;

    
amigaos_ops.to_attach_no_wait 0;

    
/* ASYNC target controls */
    
amigaos_ops.to_can_async_p NULL;
    
amigaos_ops.to_is_async_p NULL;
    
amigaos_ops.to_async NULL;
    
amigaos_ops.to_supports_non_stop NULL;

    
/* find_memory_regions support method for gcore */
    
amigaos_ops.to_find_memory_regions NULL;

    
/* make_corefile_notes support method for gcore */
    
amigaos_ops.to_make_corefile_notes NULL;

    
/* get_bookmark support method for bookmarks */
    
amigaos_ops.to_get_bookmark NULL;

    
/* goto_bookmark support method for bookmarks */
    
amigaos_ops.to_goto_bookmark NULL;

    
/* Return the thread-local address at OFFSET in the
         thread-local storage for the thread PTID and the shared library
         or executable file given by OBJFILE.  If that block of
         thread-local storage hasn't been allocated yet, this function
         may return an error.  */
    
amigaos_ops.to_get_thread_local_address NULL;

    
/* Request that OPS transfer up to LEN 8-bit bytes of the target's
         OBJECT.  The OFFSET, for a seekable object, specifies the
         starting point.  The ANNEX can be used to provide additional
         data-specific information to the target.

         Return the number of bytes actually transfered, zero when no
         further transfer is possible, and -1 when the transfer is not
         supported.  Return of a positive value smaller than LEN does
         not indicate the end of the object, only the end of the
         transfer; higher level code should continue transferring if
         desired.  This is handled in target.c.

         The interface does not support a "retry" mechanism.  Instead it
         assumes that at least one byte will be transfered on each
         successful call.

         NOTE: cagney/2003-10-17: The current interface can lead to
         fragmented transfers.  Lower target levels should not implement
         hacks, such as enlarging the transfer, in an attempt to
         compensate for this.  Instead, the target stack should be
         extended so that it implements supply/collect methods and a
         look-aside object cache.  With that available, the lowest
         target can safely and freely "push" data up the stack.

         See target_read and target_write for more information.  One,
         and only one, of readbuf or writebuf must be non-NULL.  */

    
amigaos_ops.to_xfer_partial NULL;

    
/* Returns the memory map for the target.  A return value of NULL
         means that no memory map is available.  If a memory address
         does not fall within any returned regions, it's assumed to be
         RAM.  The returned memory regions should not overlap.

         The order of regions does not matter; target_memory_map will
         sort regions by starting address.  For that reason, this
         function should not be called directly except via
         target_memory_map.

         This method should not cache data; if the memory map could
         change unexpectedly, it should be invalidated, and higher
         layers will re-fetch it.  */
    
amigaos_ops.to_memory_map NULL;

    
/* Erases the region of flash memory starting at ADDRESS, of
         length LENGTH.

         Precondition: both ADDRESS and ADDRESS+LENGTH should be aligned
         on flash block boundaries, as reported by 'to_memory_map'.  */
    
amigaos_ops.to_flash_erase NULL;

    
/* Finishes a flash memory write sequence.  After this operation
         all flash memory should be available for writing and the result
         of reading from areas written by 'to_flash_write' should be
         equal to what was written.  */
    
amigaos_ops.to_flash_done NULL;

    
/* Describe the architecture-specific features of this target.
         Returns the description found, or NULL if no description
         was available.  */
    
amigaos_ops.to_read_description NULL;

    
/* Build the PTID of the thread on which a given task is running,
         based on LWP and THREAD.  These values are extracted from the
         task Private_Data section of the Ada Task Control Block, and
         their interpretation depends on the target.  */
    
amigaos_ops.to_get_ada_task_ptid NULL;

    
/* Read one auxv entry from *READPTR, not reading locations >= ENDPTR.
         Return 0 if *READPTR is already at the end of the buffer.
         Return -1 if there is insufficient buffer for a whole entry.
         Return 1 if an entry was read into *TYPEP and *VALP.  */
    
amigaos_ops.to_auxv_parse NULL;

    
/* Search SEARCH_SPACE_LEN bytes beginning at START_ADDR for the
         sequence of bytes in PATTERN with length PATTERN_LEN.

         The result is 1 if found, 0 if not found, and -1 if there was an error
         requiring halting of the search (e.g. memory read error).
         If the pattern is found the address is recorded in FOUND_ADDRP.  */
    
amigaos_ops.to_search_memory NULL;

    
/* Can target execute in reverse?  */
    
amigaos_ops.to_can_execute_reverse NULL;

    
/* The direction the target is currently executing.  Must be
         implemented on targets that support reverse execution and async
         mode.  The default simply returns forward execution.  */
    
amigaos_ops.to_execution_direction NULL;

    
/* Does this target support debugging multiple processes
         simultaneously?  */
    
amigaos_ops.to_supports_multi_process NULL;

    
/* Does this target support enabling and disabling tracepoints while a trace
         experiment is running?  */
    
amigaos_ops.to_supports_enable_disable_tracepoint NULL;

    
/* Does this target support disabling address space randomization?  */
    
amigaos_ops.to_supports_disable_randomization NULL;

    
/* Does this target support the tracenz bytecode for string collection?  */
    
amigaos_ops.to_supports_string_tracing NULL;

    
/* Does this target support evaluation of breakpoint conditions on its
         end?  */
    
amigaos_ops.to_supports_evaluation_of_breakpoint_conditions NULL;

    
/* Does this target support evaluation of breakpoint commands on its
         end?  */
    
amigaos_ops.to_can_run_breakpoint_commands NULL;

    
/* Determine current architecture of thread PTID.

         The target is supposed to determine the architecture of the code where
         the target is currently stopped at (on Cell, if a target is in spu_run,
         to_thread_architecture would return SPU, otherwise PPC32 or PPC64).
         This is architecture used to perform decr_pc_after_break adjustment,
         and also determines the frame architecture of the innermost frame.
         ptrace operations need to operate according to target_gdbarch.

         The default implementation always returns target_gdbarch.  */
    
amigaos_ops.to_thread_architecture NULL;

    
/* Determine current address space of thread PTID.

         The default implementation always returns the inferior's
         address space.  */
    
amigaos_ops.to_thread_address_space NULL;

    
/* Target file operations.  */

    /* Open FILENAME on the target, using FLAGS and MODE.  Return a
         target file descriptor, or -1 if an error occurs (and set
         *TARGET_ERRNO).  */
    
amigaos_ops.to_fileio_open NULL;

    
/* Write up to LEN bytes from WRITE_BUF to FD on the target.
         Return the number of bytes written, or -1 if an error occurs
         (and set *TARGET_ERRNO).  */
    
amigaos_ops.to_fileio_pwrite NULL;

    
/* Read up to LEN bytes FD on the target into READ_BUF.
         Return the number of bytes read, or -1 if an error occurs
         (and set *TARGET_ERRNO).  */
    
amigaos_ops.to_fileio_pread NULL;

    
/* Close FD on the target.  Return 0, or -1 if an error occurs
         (and set *TARGET_ERRNO).  */
    
amigaos_ops.to_fileio_close NULL;

    
/* Unlink FILENAME on the target.  Return 0, or -1 if an error
         occurs (and set *TARGET_ERRNO).  */
    
amigaos_ops.to_fileio_unlink NULL;

    
/* Read value of symbolic link FILENAME on the target.  Return a
         null-terminated string allocated via xmalloc, or NULL if an error
         occurs (and set *TARGET_ERRNO).  */
    
amigaos_ops.to_fileio_readlink NULL;


    
/* Implement the "info proc" command.  */
    
amigaos_ops.to_info_proc NULL;

    
/* Tracepoint-related operations.  */

    /* Prepare the target for a tracing run.  */
    
amigaos_ops.to_trace_init NULL;

    
/* Send full details of a tracepoint location to the target.  */
    
amigaos_ops.to_download_tracepoint NULL;

    
/* Is the target able to download tracepoint locations in current
         state?  */
    
amigaos_ops.to_can_download_tracepoint NULL;

    
/* Send full details of a trace state variable to the target.  */
    
amigaos_ops.to_download_trace_state_variable NULL;

    
/* Enable a tracepoint on the target.  */
    
amigaos_ops.to_enable_tracepoint NULL;

    
/* Disable a tracepoint on the target.  */
    
amigaos_ops.to_disable_tracepoint NULL;

    
/* Inform the target info of memory regions that are readonly
         (such as text sections), and so it should return data from
         those rather than look in the trace buffer.  */
    
amigaos_ops.to_trace_set_readonly_regions NULL;

    
/* Start a trace run.  */
    
amigaos_ops.to_trace_start NULL;

    
/* Get the current status of a tracing run.  */
    
amigaos_ops.to_get_trace_status NULL;

    
amigaos_ops.to_get_tracepoint_status NULL;

    
/* Stop a trace run.  */
    
amigaos_ops.to_trace_stop NULL;

 
/* Ask the target to find a trace frame of the given type TYPE,
        using NUM, ADDR1, and ADDR2 as search parameters.  Returns the
        number of the trace frame, and also the tracepoint number at
        TPP.  If no trace frame matches, return -1.  May throw if the
        operation fails.  */
    
amigaos_ops.to_trace_find NULL;

    
/* Get the value of the trace state variable number TSV, returning
         1 if the value is known and writing the value itself into the
         location pointed to by VAL, else returning 0.  */
    
amigaos_ops.to_get_trace_state_variable_value NULL;

    
amigaos_ops.to_save_trace_data NULL;

    
amigaos_ops.to_upload_tracepoints NULL;

    
amigaos_ops.to_upload_trace_state_variables NULL;

    
amigaos_ops.to_get_raw_trace_data NULL;

    
/* Get the minimum length of instruction on which a fast tracepoint
         may be set on the target.  If this operation is unsupported,
         return -1.  If for some reason the minimum length cannot be
         determined, return 0.  */
    
amigaos_ops.to_get_min_fast_tracepoint_insn_len NULL;

    
/* Set the target's tracing behavior in response to unexpected
         disconnection - set VAL to 1 to keep tracing, 0 to stop.  */
    
amigaos_ops.to_set_disconnected_tracing NULL;
    
amigaos_ops.to_set_circular_trace_buffer NULL;

    
/* Add/change textual notes about the trace run, returning 1 if
         successful, 0 otherwise.  */
    
amigaos_ops.to_set_trace_notes NULL;

    
/* Return the processor core that thread PTID was last seen on.
         This information is updated only when:
         - update_thread_list is called
         - thread stops
         If the core cannot be determined -- either for the specified
         thread, or right now, or in this debug session, or for this
         target -- return -1.  */
    
amigaos_ops.to_core_of_thread NULL;

    
/* Verify that the memory in the [MEMADDR, MEMADDR+SIZE) range
         matches the contents of [DATA,DATA+SIZE).  Returns 1 if there's
         a match, 0 if there's a mismatch, and -1 if an error is
         encountered while reading memory.  */
    
amigaos_ops.to_verify_memory NULL;

    
/* Return the address of the start of the Thread Information Block
         a Windows OS specific feature.  */
    
amigaos_ops.to_get_tib_address NULL;

    
/* Send the new settings of write permission variables.  */
    
amigaos_ops.to_set_permissions NULL;

    
/* Look for a static tracepoint marker at ADDR, and fill in MARKER
         with its details.  Return 1 on success, 0 on failure.  */
    
amigaos_ops.to_static_tracepoint_marker_at NULL;

    
/* Return a vector of all tracepoints markers string id ID, or all
         markers if ID is NULL.  */
    
amigaos_ops.to_static_tracepoint_markers_by_strid NULL;

    
/* Return a traceframe info object describing the current
         traceframe's contents.  This method should not cache data;
         higher layers take care of caching, invalidating, and
         re-fetching when necessary.  */
    
amigaos_ops.to_traceframe_info NULL;

    
/* Ask the target to use or not to use agent according to USE.  Return 1
         successful, 0 otherwise.  */
    
amigaos_ops.to_use_agent NULL;

    
/* Is the target able to use agent in current state?  */
    
amigaos_ops.to_can_use_agent NULL;

    
amigaos_ops.to_magic 0;
    
/* Need sub-structure for target machine related rather than comm related?
     */
}

Go to top
Re: GDB
Home away from home
Home away from home


See User information
@billyfish
Thinking a bit more about: if we go the "full rewrite" route, maybe it worth doing so via v8.3 then? Or better to deal with 7.5.1 firstly, just so we will know how all things work/etc?

PS. The link on porting guide is good! It's from the year 2008, but gdb 7.5.1 is from the year 2012, but I think it's can be ok for most of the parts still.

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: GDB
Home away from home
Home away from home


See User information
@billyfish
Added your stub-code, and add also init function:

static void _initialize_amigaos_nat (void)
{
    
init_amigaos_ops();
    
add_target(&amigaos_ops);
}


And remove from exec.c adding of hooks (we need to get rid of that hack as well).

It runs, I can set a breakpoint, but when type "run", it says:

Starting program: /RAM Disk/test
target_terminal_ours()
Don't know how to run. Try "help target"

So, what next function to implement? create_inferior() ?

In porting guide saying "to_create_inferior. For targets that can execute, this initializes a program to run, ready for it to start executing. It is invoked by the GDB run command, which will subsequently call to_resume to start execution." and "The run command must create the inferior, insert any active breakpoints and watchpoints, and then start execution of the inferior. Control does not return to GDB until the target reports that it has stopped."

So probably create_inferior() is next? But we need to write it correctly now, so we will have no needs to add those ifdefs in the exec.c which feels a bit hackish. I.e. just by creating all necessary processes/subprocesses inside of amigaos-nat (just like for all other oses done). And we have no needs to use Permit/Forbid anymore too.

At first, we can just create pure "run/wait/stop" in create_inferior (without breakpoints, etc), so we will be able to just do "run" for full execute. And then go further after it works.

EDIT: tried simple:

static void amigaos_create_inferior (struct target_ops *opschar *exec_filechar *argschar **envint from_tty)
{

    
printf("Creating inferior process: exec_file = %s, args = %s, env = %p, from_tty = %ld\n"exec_fileargsenvfrom_tty);

}


...

amigaos_ops.to_create_inferior amigaos_create_inferior;

....


But nope, didn't see that printf. Seems it's not enough to just have create_inferior alone to be called, something else should be before too (or together with create_inferior)

EDIT2:

Also adding stubs for amigaos_resume(), amigaos_wait(), amigaos_stop(), amigaos_kill_inferior(), amigaos_create_inferior() and amigaos_mourn_inferior() - and nope, still "don't kow how to run. Try "help target" ". Seems something else need to be filled in.


Edited by kas1e on 2021/3/10 8:18:11
Edited by kas1e on 2021/3/10 8:32:23
Edited by kas1e on 2021/3/10 8:44:41
Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: GDB
Just popping in
Just popping in


See User information
@kas1e

You'll love the reason for this

For some, god only knows why, reason, the makefile code generation that builds and adds the calls to the initialize functions in init.c requires that the functions begin with "_initialize" and must be at the start of a line, wtf!

So if, like me, you had

void _initialize_amigaos_nat (void)
{
    
printf ("_initialize_amigaos_nat \n");
    
init_amigaos_ops ();
    
add_target (&amigaos_ops);
}


rather than

void
_initialize_amigaos_nat 
(void)
{
    
printf ("_initialize_amigaos_nat \n");
    
init_amigaos_ops ();
    
add_target (&amigaos_ops);
}


then the function call wouldn't be added to be init.c! Whoever had that as an idea, especially without explictly documenting it in big letters, is not someone I'd like working for me!

The memset call that I added without compiling yesterday had the args the wrong way around, oops!

memset (&amigaos_ops0sizeof (struct target_ops));


Now it runs to "PC register is bit available", so that's the next function to fill back in along with opening the required libs and interfaces like IElf, IDebug, IMMU, etc. which I'll add in too.


Go to top
Re: GDB
Home away from home
Home away from home


See User information
@billifish
Yeah, I can see in all the "nat" files they do it like this: with _initialize being as the beginning of the string.

And yes, tried within one line as before, and with _initialize starting form new line: GDB binary different indeed, and in the case when _initialize at the beginning of string it works then! (before I just mess it thinking it will spawn prints when I hit "run", but it of course printfs early).

Through, I still have "Don't know how to run. Try help target", probably because some other functions need to be stubbed firstly as well? Like maybe to_fileio_open, etc?

Btw, now we can see that this was correct to start from scratch :) We surely will understand it all better.

PS. if you can, do commits to your github bit by bit as well, so we will not have one big push with all the changes (so we can compare things in the process)


Quote:

along with opening the required libs and interfaces like IElf, IDebug, IMMU, etc. which I'll add in too.


In our old current GDB they opened in constuctors and closde in descructors, like:

void amigaos_pre_init(void__attribute__((constructor));
void amigaos_post_term(void__attribute__((destructor));

void amigaos_pre_init(void)
{
    
ElfBase IExec->OpenLibrary("elf.library"0);
    if (!
ElfBase)
        
error("Can't open elf.library. How did you run *this* program ?\n");
    
    
IElf = (struct ElfIFace *)IExec->GetInterface(ElfBase"main"10);
    if (!
IElf)
        
error("Can't get elf.library::main\n");
        
    
IMMU = (struct MMUIFace *)IExec->GetInterface((struct Library *)SysBase"mmu"10);
    if (!
IMMU)
        
error("Can't get MMU access\n");    
}

void amigaos_post_term(void)
{
    if (
IElf)        IExec->DropInterface((struct Interface *)IElf);
    
IElf 0;
    
    if (
ElfBase)    IExec->CloseLibrary(ElfBase);
    
ElfBase 0;
    
    if (
IMMU)        IExec->DropInterface((struct Interface *)IMMU);
    
IMMU 0;
}


Do you want to do it the same?


Edited by kas1e on 2021/3/10 12:21:29
Edited by kas1e on 2021/3/10 18:45:35
Edited by kas1e on 2021/3/10 18:50:58
Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: GDB
Just popping in
Just popping in


See User information
@kas1e


Yup that's currently how I'm doing it. I've been incrementally adding in the required functions in the order that GDB is calling them and I'm almost there in having a version that can debug a file ok. It's now becoming a lot clearer on how it's all put together so we should have a better chance of understanding what's going on as we hit each problem.

I reckon I should be able to make a pull request in the next day or two.

Go to top
Re: GDB
Home away from home
Home away from home


See User information
@billifish
Btw, I find out that for making the create_inferior call works, not only _initializ_amigaos_nat should be on a new string, but also "to_can_run" should be filled with functions returning 1, and then I meet the same "PC register is a bit available".

Will wait for your pull request then if you going pretty far already.. But if you will update in the meantime that also can be tasty to check where you are for now :)

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: GDB
Home away from home
Home away from home


See User information
@billyfish
Tried your new commit: yeah, that what I talk about! Normal proper code! We go the right way for sure!

Tested what we have now on both x5000 and pegasos2, and on both, I can load up a test file, do "list" for source code, and do "run" file, so it runs, and exit properly.

Next, I tried to set a breakpoint, and it sets, but when I do "run", it again runs the same as if I set no breakpoint and exit properly. But I assume that just because "insert/remove breakpoints" functions not implemented currently? I only can see "taget_insert_breakpoint (0x010004d4, xxx) = 0".

So, did I understand right, that the next step is re-implementing amigaos_insert_breakpoint and amigaos_remove_breakpoint?

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: GDB
Just popping in
Just popping in


See User information
@kas1e

Cheers Roman Yeah it's still missing the breakpoint stuff and dealing with the messages in amigaos_wait () for any messages that aren't CTRL+C or CTRL+D.

I don't like the is_process_alive() function and having to call it, there's got to be a cleaner way of doing that. Similarly the way that I'm getting the seglist for passing to CreateNewProcTags () could well need to be improved.

I've just added another minor commit with some minor tidying up of the code.

I haven't made a pull request yet as the code is only half finished, if you want me to I can though, just say the word.

Go to top
Re: GDB
Home away from home
Home away from home


See User information
@billyfish
Quote:

Yeah it's still missing the breakpoint stuff and dealing with the messages in amigaos_wait () for any messages that aren't CTRL+C or CTRL+D.


Do you think messages is important enough for now, or can wait in favor of breakpoints stuff ? (just with breakpoints stuff added, we can see all the issues left : i.e. if "bt" will works, if "show regs" will works, "disas" , stepping into systemcalls inside the kernel, etc,etc.


Quote:

I don't like the is_process_alive() function and having to call it, there's got to be a cleaner way of doing that. Similarly the way that I'm getting the seglist for passing to CreateNewProcTags () could well need to be improved.


Yeah, i noticed how you deal with SegList stuff, damn, it was really hacky before ! Why it wasn't like this, in clear way .. Probabaly just because it were done 15 years ago, and Thomas did it just like this just "So it works somehow".


Quote:

I haven't made a pull request yet as the code is only half finished, if you want me to I can though, just say the word.



Imho just after breakpoint stuff added we can pull request it: it then will be "kind of first working version", and then we will be able to check if x5000 will still fail (probabaly it will), but we will know wtf for now, as its all our new code.

At least we will be able to ask Thomas and other kernel-devs with having proper test-cases :)


EDIT: Btw, do you have a paypal acc ? Want to donate a bit for the work you already do and will happy to donate from time to time if we can deal to some working version :)


Edited by kas1e on 2021/3/12 18:40:13
Edited by kas1e on 2021/3/12 19:12:58
Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: GDB
Just popping in
Just popping in


See User information
@kas1e

Quote:

Do you think messages is important enough for now, or can wait in favor of breakpoints stuff ?


Can do, the messages will mainly be for exceptions like null pointer crashes or memory access errors. Should be easy to add in but no need to hold up breakpoints for it. So my current plan is make sure the elf relocation code is correct, as the breakpoint stuff needs that, then the breakpoints can go in. The messages handling would be pretty quick after that. The next part would be the partial memory transfer stuff which is the part of the updated gdb API which the old port didn't have.

Quote:

: Btw, do you have a paypal acc ? Want to donate a bit for the work you already do and will happy to donate from time to time if we can deal to some working version :)


Thanks Roman, however there's really no need. The reward of having an actual working debugger will be more than enough!
🙂

If we can get this working then development will become soooooo much easier. Personally I should be able to make much more progress on porting the latest libgit2 stuff, etc.

Go to top
Re: GDB
Home away from home
Home away from home


See User information
@billifish
Quote:

So my current plan is make sure the elf relocation code is correct, as the breakpoint stuff needs that, then the breakpoints can go in.


I check in old 6.3a sources amigaos_memory_insert_breakpoint(), and it didn't look like something _VERY_ hardcore. Mainly some relocation, then going to a superstate, save some bits, write breakpoint, restore some bits, and back to the user state.

Then check how it did on morphos: there I can't find at all this kind of functions, seems it all now "under the hood" somewhere else.

And checked then alfkil's DB101 https://github.com/adtools/db101

There check src/suspedn.c , it also has memory_insert_breakpoint(), and that how it looks like:

int memory_insert_breakpoint(uint32 addruint32 *buffer)
{
  
uint32 oldAttr;
  
APTR stack;

dprintf("Setting BP at 0x%x\n"addr);

  
/* Write the breakpoint.  */
  
if (1)
  {
      
/* Go supervisor */
    
stack IExec->SuperState();

      
/* Make sure to unprotect the memory area */
    
oldAttr IMMU->GetMemoryAttrs((APTR)addr0);
    
IMMU->SetMemoryAttrs((APTR)addr4MEMATTRF_READ_WRITE);

#if 1
        
*buffer = *(uint32 *)addr;
        *(
uint32 *)addr meth_start;    //insert asm("trap")
        //dprintf("buffer: 0x%x meth_start: 0x%x addr:0x%x\n", *buffer, meth_start, addr);
#else
        
uint32 realaddr = (uint32)IMMU->GetPhysicalAddress((APTR)addr);
        if(
realaddr == 0x0)
            
realaddr addr;
        
//dprintf("Setting bp at 0x%x\n", realaddr);
        
*buffer setbreak(realaddrmeth_start);
#endif

    /* Set old attributes again */
    
IMMU->SetMemoryAttrs((APTR)addr4oldAttr);
    
    
/* Return to old state */
    
if (stack)
        
IExec->UserState(stack);
  }
  
IExec->CacheClearU();

  return 
0;
}


See, the same way how done in old GDB 6.3a, just a bit more clean code.

And Alfkil's spotless one:

int Breaks::memory_insert_break_instruction (uint32_t addressuint32_t *buffer)
{
    
/* Go supervisor */
    
APTR stack IExec->SuperState();

    
/* Make sure to unprotect the memory area */
    
uint32 oldAttr IMMU->GetMemoryAttrs ((APTR)address0);
    
IMMU->SetMemoryAttrs ((APTR)address4MEMATTRF_READ_WRITE);

    
uint32_t realAddress = (uint32_t)IMMU->GetPhysicalAddress ((APTR)address);
    if (
realAddress == 0x0)
        
realAddress address;

    
int hallo meth_start;
    *
buffer setbreak (realAddressmeth_start);

    
IExec->CacheClearE((APTR)address0xffffffffCACRF_ClearICACRF_ClearD);

    
/* Set old attributes again */
    
IMMU->SetMemoryAttrs ((APTR)address4oldAttr);

    
/* Return to old state */
    
if (stackIExec->UserState (stack);

    return 
0;
}


So everywhere all the same. Just in SpotLess version seems a bit more "full" and in both DB101 and SpotLess he didn't do any address relocation (but that maybe done somewhere else in deep of code) ? Or maybe relocation in Alfkil's code is just this :

Quote:

if (realAddress == 0x0)
realAddress = address;



Join us to improve dopus5!
AmigaOS4 on youtube
Go to top

  Register To Post
« 1 ... 3 4 5 (6) 7 8 9 10 »

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project