WEB开发网
开发学院操作系统Linux/Unix 在 AIX 中建立特定于产品的调试器 阅读

在 AIX 中建立特定于产品的调试器

 2009-07-15 08:33:40 来源:WEB开发网   
核心提示: 这个过程非常麻烦,必须多次运行 print 命令,在 AIX 中建立特定于产品的调试器(6),每次显示一个节点,如果列表包含大量节点,在这段代码中,实现了插件必需具有的一些例程,那么调试会花费大量时间,非常麻烦

这个过程非常麻烦,必须多次运行 print 命令,每次显示一个节点。如果列表包含大量节点,那么调试会花费大量时间,非常麻烦。

为了解决这个问题,可以设计一个插件,可以使用它以更快更智能化的方式调试和分析此程序。

用于调试示例程序的 dbx 插件的代码

本节给出一个插件的代码片段,此插件用于调试前面的示例应用程序。此插件由 “example.c” 和 “example.exp” 文件组成。

下面是 example.c 文件的代码。在这段代码中,实现了插件必需具有的一些例程。还实现了一个从示例程序收集并输出信息的例程。

/* Program to make a dbx plug-in, to debug a sample program.  */ 
 
/* Header files required for dbx plug-in */ 
#include<sys/dbx_plugin.h> 
 
/* Header files required to get the sample program structure information  */ 
#include"list.h" 
 
/* Plug-in session and service handles */ 
dbx_plugin_session_t sid; 
dbx_plugin_services_t dbx; 
 
/* Routines for handling commands */ 
static void usage(void); 
static void list_cmd(void); 
 
/* Routine to get dbx plug-in version number */ 
/* Note: Each plug-in must implement and export this function */ 
int 
dbx_plugin_version(void) 
{ 
  return DBX_PLUGIN_VERSION_1; 
} 
 
/* Routine to initialize plug-in session and service handles */ 
/* Note: Each plug-in must implement and export this function */ 
int 
dbx_plugin_session_init(dbx_plugin_session_t session, 
              const dbx_plugin_services_t *servicep) 
{ 
  /* record session identifier */ 
  sid = session; 
 
  /* record dbx service */ 
  memcpy(&dbx, servicep, sizeof(dbx_plugin_services_t)); 
 
  /* create an alias "printlist" to the command "plugin example printlist" */ 
  (*(dbx.alias))(sid, "printlist", "plugin example printlist"); 
 
  return 0; 
} 
 
/* Routine to dispatch the command */ 
/* Note: Each plug-in must implement and export this function */ 
void 
dbx_plugin_session_command(dbx_plugin_session_t session, 
              int argc, 
              char *const argv[]) 
{ 
  /* display the usage */ 
  if (argc == 0 || (argc == 1 && strcmp(argv[0], "help") == 0)) { 
    usage(); 
    return; 
  } 
 
  /* execute the command printlist */ 
  if (argc == 1 && strcmp(argv[0], "printlist") == 0) { 
    list_cmd(); 
    return; 
  } 
 
  (*(dbx.print))(sid,DBX_PLUGIN_PRINT_MODE_ERR, 
            "unrecognized command\n"); 
 
} 
 
/* Routine to handle the event notifications */ 
/* Note: Each plug-in must implement and export this function */ 
void 
dbx_plugin_session_event(dbx_plugin_session_t session, 
             int event, 
             dbx_plugin_event_info_t *event_infop) 
{ 
  /* ignore event notifications */ 
} 
 
/* Routine the do exit cleanup */ 
void 
dbx_plugin_session_destroy(dbx_plugin_session_t session) 
{ 
  /* no clean up to perform */ 
} 
 
/* Routine to print the usage of plug-in */ 
static void 
usage(void) 
{ 
  (*(dbx.print))(sid,DBX_PLUGIN_PRINT_MODE_OUT, 
            "Subcommands for Plug-in \"example\":\n\n" \ 
            "  help - displays this output\n" \ 
            "  printlist - display complete linked list \n" \ 
            "\n"); 
} 
 
/* Routine to fetch the address of List symbol, and then read the 
  contents of each node and print all of them.          */ 
static void 
list_cmd(void) 
{ 
  int res; 
  struct List *node = (struct List *) malloc(sizeof(struct List)); 
  unsigned long long int addr; 
  unsigned int listp; 
 
  /* Locate address of "List" symbol. */ 
  dbx_plugin_syminfo_t sym = { "List", 1, -1 } ; 
 
  res = (*(dbx.locate_symbol))(sid, &sym, sizeof(sym), 1); 
  if(res != DBX_PLUGIN_SUCCESS) { 
    printf("Symbol not found!!! return code: 0x%x\n", res); 
    return; 
  } 
 
  /* read the contents of the symbol "List". It would be the 
    address of the first node of the list           */ 
  (*(dbx.read_memory))(sid, sym.addr, (void *)&listp, sizeof(listp)); 
 
  addr = (unsigned long long int)listp; 
 
  printf("------Printing List -------\n"); 
 
  while(addr) 
  { 
    /* read the list node contents, and display it. */ 
    (*(dbx.read_memory))(sid, addr, (void *)node, sizeof(struct List)); 
 
    printf("Node : 0x%llx\n Info : %d\n", 
        addr, node->info); 
 
    /* move to next node */ 
     addr = (unsigned long long int)node->next; 
  } 
} 
 
   

上一页  1 2 3 4 5 6 7  下一页

Tags:AIX 中建 立特

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接