⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gdb_c_test.c

📁 lwip在ucos上的移植
💻 C
📖 第 1 页 / 共 5 页
字号:
    {      *p_out++ = '+';      ++length;    }    gdb_cat_ack = NO;    *p_out++ = '$';    ++length;    checksum = 0;    while ( *str )    {      *p_out++ = *str;      ++length;      checksum += *str++;    }    *p_out++ = '#';    *p_out++ = hexchars[checksum >> 4];    *p_out = hexchars[checksum % 16];    length += 3;    eth_to_gdb( (UCHAR *) eth_outbuffer, length );  }  else  {      /* via RS-232 */    do {      LAN_PUT_CHAR( '$' );      checksum = 0;      while ( *str )        {          LAN_PUT_CHAR( *str );          checksum += *str++;        }      LAN_PUT_CHAR( '#' );      LAN_PUT_CHAR( hexchars[checksum >> 4] );      LAN_PUT_CHAR( hexchars[checksum % 16] );    } while ( 0 /* get_debug_char( ) != '+' */ );    /* XXX FIXME: not waiting for the ack. */  }}/*----------------------------------------------------------------------------- * * FUNCTION NAME:   gdb_get_eth_input * * * DESCRIPTION: * * * RETURN VALUE:    None. * * * USED GLOBAL VARIABLES: * * * AFFECTED GLOBAL VARIABLES/SIDE EFFECTS: * * * NOTES: * * *---------------------------------------------------------------------------*/void    gdb_get_eth_input( unsigned char *buf, long length ){  gdb_host_comm = VIA_ETHERNET;  for ( ; 0 < length; ++buf, --length)  {    if ( *buf == CONTROL_C )    {        /* can't stop the target, but we can tell gdb to stop waiting... */      discard_packet( );      putpacket( "S03" );       /* send back SIGINT to the debugger */    }    else    {      lan_add_to_queue( (long) *buf, &lan_input_queue );      get_gdb_input( (long) *buf, &lan_input_queue );    }  }  return;}/* end of 'gdb_get_eth_input' *===========================================================================*//* STDOUT STDOUT STDOUT STDOUT STDOUT STDOUT STDOUT STDOUT STDOUT STDOUT   Stuff pertaining to simulating stdout by sending chars to gdb to be echoed.   Dear reader:       This code is based on the premise that if GDB receives a packet   from the stub that begins with the character CAPITAL-OH, GDB will   echo the rest of the packet to GDB's console / stdout.  This gives   the stub a way to send a message directly to the user.  In practice,   (as currently implemented), GDB will only accept such a packet when   it believes the target to be running (ie. when you say STEP or   CONTINUE); at other times it does not expect it.  This will probably   change as a side effect of the "asynchronous" behavior.   Functions: gdb_putchar(char ch)              gdb_write(char *str, int len)              gdb_puts(char *str)              gdb_error(char *format, char *parm) */#if 0 /* avoid compiler warning while this is not used *//* Function: gdb_putchar(int)   Make gdb write a char to stdout.   Returns: the char */static intgdb_putchar( long ch ){  char buf[4];  buf[0] = 'O';  buf[1] = hexchars[ch >> 4];  buf[2] = hexchars[ch & 0x0F];  buf[3] = 0;  putpacket( buf );  return ch;}#endif/* Function: gdb_write(char *, int)   Make gdb write n bytes to stdout (not assumed to be null-terminated).   Returns: number of bytes written */static intgdb_write( char *data, long len ){  char *buf, *cpy;  long i;  buf = outbuffer;  buf[0] = 'O';  i = 0;  while ( i < len )    {      for ( cpy = buf+1;           i < len && cpy < buf + BUFMAX - 3;           i++ )        {          *cpy++ = hexchars[data[i] >> 4];          *cpy++ = hexchars[data[i] & 0x0F];        }      *cpy = 0;      putpacket( buf );    }  return len;}/* Function: gdb_puts(char *)   Make gdb write a null-terminated string to stdout.   Returns: the length of the string */static intgdb_puts( char *str ){  return gdb_write( str, strlen( str ) );}/* Function: gdb_error(char *, char *)   Send an error message to gdb's stdout.   First string may have 1 (one) optional "%s" in it, which   will cause the optional second string to be inserted.  */#if 0static voidgdb_error( char *format, char *parm ){  static char buf[400];  char *cpy;  long len;  if ( remote_debug )    {      if ( format && *format )        len = strlen( format );      else        return;             /* empty input */      if ( parm && *parm )        len += strlen( parm );      for ( cpy = buf; *format; )        {          if ( format[0] == '%' && format[1] == 's' ) /* include 2nd string */            {              format += 2;          /* advance two chars instead of just one */              while ( parm && *parm )                *cpy++ = *parm++;            }          else            *cpy++ = *format++;        }      *cpy = '\0';      gdb_puts( buf );    }}#endifstatic void gdb_note (char *, int);static int  error_ret (int, char *, int);static unsigned longelinum_to_index (unsigned long elinum){  if ((elinum & 0xf0) == 0xd0)    return (elinum & 0x0f);  else if ((elinum & 0xf0) == 0xa0)    return (elinum & 0x0f) + 8;  else    return -1;}static longindex_to_elinum (unsigned long index){  if (index <= 7)    return index + 0xd0;  else if (index <= 15)    return (index - 8) + 0xa0;  else    return -1;}/*  READMEM READMEM READMEM READMEM READMEM READMEM READMEM READMEM READMEM  The following code pertains to reading memory from the target.  Some sort of exception handling should be added to make it safe.  READMEM READMEM READMEM READMEM READMEM READMEM READMEM READMEM READMEM  Safe Memory Access:  All reads and writes into the application's memory will pass thru  get_uchar() or set_uchar(), which check whether accessing their  argument is legal before actual access (thus avoiding a bus error).  */enum { SUCCESS = 0, FAIL = -1 };#if 0static long get_uchar ( const unsigned char * );#endifstatic long set_uchar ( unsigned char *, unsigned char );static long read_access_violation ( const void * );static long write_access_violation ( const void * );static long read_access_range(const void *, long);static DTC_RESPONSE find_memory(unsigned char *,long,unsigned char **,long *);static intdtc_error_ret (int ret, char *src, DTC_RESPONSE code){  if (src)    sprintp (spare_buffer,             "'%s' returned DTC error '%s'.\n", src, get_err_text (code));  else    sprintp (spare_buffer, "DTC error '%s'.\n", get_err_text (code));  gdb_puts (spare_buffer);  return ret;}#if 0/* I think this function is unnecessary since the introduction of   adbg_find_memory_addr_in_frame.  *//* Return the number of expressions in the format associated with a   given trace frame.  */static intcount_frame_exprs (FRAME_DEF *frame){  CFD *format;  T_EXPR *expr;  int num_exprs;  /* Get the format from the frame.  */  get_frame_format_pointer (frame, &format);  /* Walk the linked list of expressions, and count the number of     expressions we find there.  */  num_exprs = 0;  for (expr = format->p_cfd_expr; expr; expr = expr->next)    num_exprs++;  return num_exprs;}#endif#if 0/* Function: get_frame_addr * * Description: If the input memory address was collected in the *     current trace frame, then lookup and return the address *     from within the trace buffer from which the collected byte * may be retrieved.  Else return -1.  */unsigned char *get_frame_addr ( const unsigned char *addr ){  unsigned char *base, *regs, *stack, *mem;  CFD *dummy;  DTC_RESPONSE ret;  /* first, see if addr is on the saved piece of stack for curframe */  if (curframe.format->stack_size > 0 &&      (base = (unsigned char *) curframe.traceregs[A7]) <= addr  &&      addr < base + curframe.format->stack_size)    {      gdb_puts("STUB: get_frame_addr: call get_addr_to_frame_regs_stack_mem\n");      if ((ret = get_addr_to_frame_regs_stack_mem (curframe.frame_data,						   &dummy,						   (void *) &regs,						   (void *) &stack,                                                   (void *) &mem))          != OK_TARGET_RESPONSE)        return (void *) dtc_error_ret (-1,                                       "get_addr_to_frame_regs_stack_mem",                                       ret);      else        return stack + (addr - base);    }  /* Next, try to find addr in the current frame's expression-     collected memory blocks.  I'm sure this is at least quadradic in     time.  */  {    int num_exprs = count_frame_exprs (curframe.frame_data);    int expr, block;    /* Try each expression in turn.  */    for (expr = 0; expr < num_exprs; expr++)      {	for (block = 0; ; block++)	  {	    T_EXPR_DATA *data;	    if (adbg_get_expr_data (curframe.frame_data,				    'x', expr, block,				    &data)		!= OK_TARGET_RESPONSE)	      break;	    else if ((unsigned char *) data->address <= addr		     && addr < ((unsigned char *) data->address + data->size))	      {		/* We have found the right block; is it valid data?		   Upper-case stamps mean bad data.  */		if ('A' <= data->stamp && data->stamp <= 'Z')		  {		    gdb_puts("STUB: get_frame_addr: adbg_get_expr_data INVALID\n");		    return (unsigned char *) -1;		  }		else		  {		    if (remote_debug > 1)		      {			sprintp(spare_buffer,				"STUB: get_frame_addr: got it [%x,%x)\n",				data->address, data->address + data->size);			gdb_puts(spare_buffer);		      }		    return (((unsigned char *) &data->data)			    + (addr - (unsigned char *) data->address));		  }	      }	  }      }  }  /* not found, return error */  return (unsigned char *) -1;}/*============================================================*/static long get_uchar ( const unsigned char * addr ){  unsigned char *frame_addr;  if ( read_access_violation ( addr ) )    return ( -1 ); /* Access error */  if (curframe.valid)   /* if debugging a trace frame? */    {      /* If the requested address was collected in the current frame,       * then fetch and return the data from the trace buffer.       */      if ((frame_addr = get_frame_addr (addr)) != (unsigned char *) -1)        return ( *frame_addr );      /* If the requested address is in the Code Section,       * let's be magnanimous and read it anyway (else we shall       * not be able to disassemble, find function prologues, etc.)       */      else if (CS_CODE_START <= (unsigned long) addr &&               (unsigned long) addr < CS_CODE_START + CS_CODE_SIZE)        return (*addr);      else        return ( -1 );  /* "Access error" (the data was not collected) */    }  else    /* Not debugging a trace frame, read the data from live memory. */    return ( *addr ); /* Meaningful result >= 0 */}#endif/*============================================================*/static long set_uchar ( unsigned char * addr, unsigned char val ){  long check_result = write_access_violation ( addr );  if ( check_result != 0L )    return ( check_result ); /* Access error */  return ( *addr = val );    /* Successful writing */}/*============================================================*//* * Function read_access_violation() below returns TRUE if dereferencing * its argument for reading would cause a bus error - and FALSE otherwise: */static long read_access_violation ( const void * addr ){  return ( ( ( addr < SRAM_START ) || ( addr >= SRAM_END ) ) &&           ( ( addr < NVD_START )  || ( addr >= NVD_END ) ) );}/*============================================================*//* * Function write_access_violation() below returns zero if dereferencing * its argument for writing is safe, -1 on a soft error (the argument * falls into the write-protected area), -2 on a hard error (the argument * points to a non-existent memory location). In other words, it returns * FALSE when no bus error is expected - and an error code otherwise: */static long write_access_violation ( const void * addr ){  /*   * The boundaries of the write-protected area have to be received via   * an API provided in the Symmetrix core code. For now, these limits   * are hard-coded:   */  if ( ( addr >= RO_AREA_START ) && ( addr < RO_AREA_END ) )    return ( -1 ); /* soft error */  if ( ( ( addr < SRAM_START ) || ( addr >= SRAM_END ) ) &&       ( ( addr < NVD_START )  || 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -