Example #1
0
static struct procdata_s *regm_Pass1Node(poffHandle_t hPoff,
                                         uint32_t dwStartOffset,
                                         uint32_t pdwEndOffset,
                                         uint8_t chTerminator)

{
  struct procdata_s *pNode;
  uint32_t dwActualEndOffset;

  TRACE(stderr, "[regm_Pass1Node]");

  /* Create a container for the proc/func body, and read the data */

  pNode = regm_CreateProgSection();

  /* Check if there is a jump at the beginning of the segment */

  pNode->section[0].dwOffset = dwStartOffset;
  pNode->section[1].dwOffset = regm_CheckSection1(hPoff, dwStartOffset);

  /* Read all of the p-codes associated with the node */

  dwActualEndOffset = regm_ReadNodePCodes(pNode, hPoff,
                                          pNode->section[1].dwOffset,
                                          pdwEndOffset, chTerminator);

  /* Now calculate the size of each part of the program section */

  pNode->section[1].dwSize = dwActualEndOffset - pNode->section[1].dwOffset;

  if (pNode->section[0].dwOffset == pNode->section[1].dwOffset)
    pNode->section[0].dwSize = 0;
  else
    pNode->section[0].dwSize = 5;

  /* Associate debug info with the program section. */

  pNode->pFuncInfo = poffFindDebugFuncInfo(pNode->section[0].dwOffset);
  if (!pNode->pFuncInfo)
    {
      /* This debug information should always be present at this
       * point.  We will need it.
       */

      fatal(ePOFFCONFUSION);
    }

  return pNode;
}
Example #2
0
static void dumpProgramData(poffHandle_t poffHandle)
{
  poffLibLineNumber_t *lastln;     /* Previous line number reference */
  poffLibLineNumber_t *ln;         /* Current line number reference */
  poffLibDebugFuncInfo_t *dfi;     /* Current line debug info */
  uint32_t pc;                      /* Program counter */
  int     opSize;                  /* Size of the opcode */
  int     inch;                    /* Input char */
  OPTYPE  op;                      /* opcode */

  /* Read the line number entries from the POFF file */

  poffReadLineNumberTable(poffHandle);

  /* Read the debug function information from the POFF file */

  poffReadDebugFuncInfoTable(poffHandle);

  /* Dump the program data section -- DumpProgramData Loop */

  pc     = 0;
  lastln = NULL;

  while ((inch = poffGetProgByte(poffHandle)) != EOF)
    {
      /* Get opcode arguments (if any) */

      op.op  = inch;
      opSize = 1;

      if (inch & o32)
        {
          uint32_t arg;

          /* Handle 32-bits in big endian byte stream */

          arg  = poffGetProgByte(poffHandle) << 24;
          arg |= poffGetProgByte(poffHandle) << 16;
          arg |= poffGetProgByte(poffHandle) <<  8;
          arg |= poffGetProgByte(poffHandle);

          op.arg  = arg;
          opSize += 4;
        }

      /* Check for debug information associated with this line */

      dfi = poffFindDebugFuncInfo(pc);
      if (dfi)
        {
          int i;
          if (dfi->retsize)
            {
              printf("\nFUNCTION ENTRY:  return size=%ld nparms=%ld\n",
                     dfi->retsize, dfi->nparms);
            }
          else
            {
              printf("\nPROCEDURE ENTRY: nparms=%ld\n", dfi->nparms);
            }

          for (i = 0; i < dfi->nparms; i++)
            {
              printf("Argument %2d:     size=%ld\n", i, dfi->argsize[i]);
            }
        }

      /* Find the line number associated with this line */

      ln = poffFindLineNumber(pc);
      if ((ln) && (ln != lastln))
        {
          /* Print the line number line */

          printf("\n%s:%ld\n", ln->filename, ln->lineno);

          /* This will suppress reporting the same line number
           * repeatedly.
           */

          lastln = ln;
        }

      /* Print the address then the opcode on stdout */

      fprintf(stdout, "%08lx ", pc);
      insn_DisassemblePCode(stdout, &op);

      /* Bump the PC to the next address */

      pc += opSize;

    } /* end while */

  /* Release buffers associated with line number and debug information */

  poffReleaseLineNumberTable();
  poffReleaseDebugFuncInfoTable();

} /* end dumpProgramData */