Example #1
0
int main(int argc, const char* argv[])
{
	const char* filename = argv[1];
	const char *target = "elf64-x86-64";
	
	bfd *abfd;
	bfd_init();
	abfd = bfd_openr(filename, target);
	if (abfd == NULL) { fprintf(stderr, "getsyms: '%s' : No such file", filename); return 0;  }
	bfd_check_format(abfd, bfd_object);
	dump_symbols(abfd);	
	return 0;
}
Example #2
0
/*
 * Finish building grammar
 */
void
grammar_complete(struct grammar *grammar)
{
    resolve_symbols(grammar);
    determine_start(grammar);
    add_sentinel_rule(grammar);
    count_symbols(grammar);
    /* At this point we have complete symbol graph */

    if (print_opt(P_GRAMMAR))
        dump_grammar(grammar);
    if (print_opt(P_SYMBOLS))
        dump_symbols(grammar);

    nullable_find(grammar);

    if (print_opt(P_NULLABLE))
        nullable_dump(grammar);
}
Example #3
0
int
main(int argc, char *argv[])
{
  int c;
  gp_boolean usage = false;
  int display_flags;

  char temp_buf[12];
  char *processor_name;
  const struct px *processor_info;
  proc_class_t processor_class;

  gp_init();

#define DISPLAY_NOTHING 0
#define DISPLAY_DIR     1
#define DISPLAY_SYM     2
#define DISPLAY_ROM     4
#define DISPLAY_SRC     8
#define DISPLAY_MESS    16
#define DISPLAY_ALL     0xff

  display_flags = DISPLAY_NOTHING;
  while ((c = getopt_long(argc, argv, GET_OPTIONS, longopts, NULL)) != EOF) {
    switch (c) {
    case '?':
    case 'h':
      usage = true;
      break;

    case 'a':
      display_flags = DISPLAY_ALL;
      break;

    case 'd':
      display_flags |= DISPLAY_DIR;
      break;

    case 's':
      display_flags |= DISPLAY_SYM;
      break;

    case 'r':
      display_flags |= DISPLAY_ROM;
      break;

    case 'l':
      display_flags |= DISPLAY_SRC;
      break;

    case 'm':
      display_flags |= DISPLAY_MESS;
      break;

    case 'v':
      fprintf(stderr, "%s\n", GPVC_VERSION_STRING);
      exit(0);
    }

    if (usage) {
      break;
    }
  }

  if ((optind + 1) == argc) {
    strncpy(filename, argv[optind], sizeof(filename));
  }
  else {
    usage = 1;
  }

  if (display_flags == DISPLAY_NOTHING) {
    display_flags = DISPLAY_ALL;
  }

  if (usage) {
    show_usage();
  }

  codefile = fopen(filename,"rb");
  if (codefile == NULL) {
    perror(filename);
    exit(1);
  }

  /* Start off by reading the directory block */
  main_dir = read_directory();

  /* Determine if byte address and org are different */
  processor_name = substr(temp_buf,
                          sizeof(temp_buf),
                          &main_dir->dir[COD_DIR_PROCESSOR],
                          8);

  processor_info = gp_find_processor(processor_name);
  processor_class = gp_processor_class(processor_info);

  if (display_flags & DISPLAY_DIR) {
    dump_directory_blocks();
  }

  if (display_flags & DISPLAY_ROM) {
    dump_code(processor_class);
  }

  if (display_flags & DISPLAY_SYM) {
    dump_symbols();
    dump_lsymbols();
    dump_local_vars(processor_class);
  }

  dump_source_files();

  if (display_flags & DISPLAY_SRC) {
    dump_line_symbols();
  }

  if (display_flags & DISPLAY_MESS) {
    dump_message_area();
  }

  return EXIT_SUCCESS;
}
Example #4
0
int main(int argc,char *argv[]){
	dump_symbols(argv[0]);
	return 0;
}
Example #5
0
int main(int argc, char *argv[])
{
  extern int optind;
  unsigned int buffer_size;
  int c,usage=0;
  int display_flags;
  Directory *dir;

  gp_init();

  byte_addr = 0;

#define DISPLAY_NOTHING 0
#define DISPLAY_DIR     1
#define DISPLAY_SYM     2
#define DISPLAY_ROM     4
#define DISPLAY_SRC     8
#define DISPLAY_MESS    16
#define DISPLAY_ALL     0xff

  display_flags = DISPLAY_NOTHING;
  while ((c = GETOPT_FUNC) != EOF) {
    switch (c) {
    case '?':
    case 'h':
      usage = 1;
      break;
    case 'a':
      display_flags = DISPLAY_ALL;
      break;
    case 'd':
      display_flags |= DISPLAY_DIR;
      break;
    case 's':
      display_flags |= DISPLAY_SYM;
      break;
    case 'r':
      display_flags |= DISPLAY_ROM;
      break;
    case 'l':
      display_flags |= DISPLAY_SRC;
      break;
    case 'm':
      display_flags |= DISPLAY_MESS;
      break;
    case 'v':
      fprintf(stderr, "%s\n", GPVC_VERSION_STRING);
      exit(0);
    }
    if (usage)
      break;
  }
  
  if ((optind + 1) == argc)
    strncpy(filename, argv[optind], sizeof(filename));
  else
    usage = 1;

  if(display_flags == DISPLAY_NOTHING)
    display_flags = DISPLAY_ALL;

  if (usage) {
    show_usage();
  }

  codefile = fopen(filename,"rb");
  if(codefile == NULL) {
    perror(filename);
    exit(1);
  }

  /* Start off by reading the directory block */
  read_directory();

  fseek(codefile, 0,SEEK_SET);
  buffer_size = fread(directory_block_data, 1, COD_BLOCK_SIZE, codefile);

  if(display_flags & DISPLAY_DIR)
    directory_block();

  dir = (Directory *)directory_block_data;

  if(display_flags & DISPLAY_ROM)
    dump_code();

  if(display_flags & DISPLAY_SYM) {
    dump_symbols();
    dump_lsymbols();
    dump_local_vars();
  }

  dump_source_files();

  if(display_flags & DISPLAY_SRC)
    dump_line_symbols();

  if(display_flags & DISPLAY_MESS)
    dump_message_area();

  return EXIT_SUCCESS;
}
Example #6
0
File: pass2.c Project: wacke/g21k
short pass2( void )
{
    short int                i;
    unsigned short           reloc;
    register SCNHDR         *sec_hdr_ptr;
    register SEC_DATA       *sec_data_ptr;
    register unsigned long  size;
    SYMBOL                  *sym;
    long                     where_we_were;
    char                     section_name[SYMNMLEN + 1];

    pass = 2;
    size = 0;
    section_name[SYMNMLEN] = '\0';

    for( i = 1, sec_hdr_ptr = &section_header[1]; i <= (short) section_cnt; 
         ++i, ++sec_hdr_ptr )
    {
         strncpy( section_name, sec_hdr_ptr->s_name, SYMNMLEN);
         sym = symbol_lookup( section_name );
	 if( NULL == sym )
          FATAL_ERROR("Couldn't find section header in symbol table - pass2.c:pass2()");
	   
         sym->value = 0L;

         if( i > 1 )
             update_symbol_table( 0L, (long) size, (long) i );

         size  += (sec_hdr_ptr->s_size
                   / ((sec_hdr_ptr->s_flags & SECTION_PM) == SECTION_PM
                      ? PM_WORD_SIZE : DM_WORD_SIZE));
    }         

    if( (obj_fd = fopen( obj_name, UPDATE_BINARY )) == NULL )
    {
          FATAL_ERROR("Error opening object file");
    }

    header_ptr = ftell( obj_fd );

    /* Seek past the object file and section headers so we can write the
     * the raw data for each section.
     */

    fseek( obj_fd, (long)(header_ptr + FILHSZ + AOUTSZ + section_cnt *
                          SCNHSZ), 0 );

    glob_sym_fd = temp_file_create( WRITE_BINARY );
    glob_sym_temp_index = num_open_files - 1;

    stat_sym_fd = temp_file_create( WRITE_BINARY );
    stat_sym_temp_index = num_open_files - 1;

    sym_fd      = temp_file_create( WRITE_BINARY );
    sym_temp_index = num_open_files - 1;

    rel_fd      = temp_file_create( WRITE_BINARY );
    rel_temp_index = num_open_files - 1;

    line_fd     = temp_file_create( WRITE_BINARY );
    line_temp_index = num_open_files - 1;

    reloc = 0;
    size = 0;
    for( i = 1, sec_hdr_ptr = &section_header[1], sec_data_ptr =
         &section_data[1]; i <= (short) section_cnt; ++i, ++sec_hdr_ptr, ++sec_data_ptr )
    {
         num_line = 0;
         num_reloc = 0;

         /* Code generation time */

         code_process( temp_file[sec_data_ptr->temp_file_index], (long) size, i );

         sec_hdr_ptr->s_nlnno = (unsigned short) num_line;
         sec_hdr_ptr->s_nreloc = (unsigned short) num_reloc;
         reloc += sec_hdr_ptr->s_nreloc;
         size  += (sec_hdr_ptr->s_size
                   / ((sec_hdr_ptr->s_flags & SECTION_PM) == SECTION_PM
                      ? PM_WORD_SIZE : DM_WORD_SIZE));
    }

    fixup_symbol_table( sym_fd );
    flush_files();

    /* Write the finished table to the symbol table file */

    if( (glob_sym_fd = fopen(temp_file[glob_sym_temp_index], READ_BINARY )) == NULL )
         FATAL_ERROR("Error opening global symbol temp file");

    if( (stat_sym_fd = fopen(temp_file[stat_sym_temp_index], READ_BINARY )) == NULL )
         FATAL_ERROR("Error opening static symbol temp file");

    dump_symbols();
    fclose( glob_sym_fd );
    fclose( stat_sym_fd );

    fflush( sym_fd );
    fclose( sym_fd );

    /* Write the object file header and the section headers */

    where_we_were = ftell( obj_fd );
    fseek( obj_fd, 0L, 0 );
    object_headers();

    fseek( obj_fd, where_we_were, 0 );

    /* Write the relocation info to the object file */

    if( (rel_fd = fopen(temp_file[rel_temp_index], READ_BINARY)) == NULL )
         FATAL_ERROR("Error opening temp relocation file");
    write_all_relocation_info( (long) reloc );
    fclose( rel_fd );

    if( !check_if_errors() )
    {
        /* Append the line number entries, symbol table, and string table
         * to the end of the object file.
         */

        copy_section( temp_file[line_temp_index] );
        copy_section( temp_file[sym_temp_index] );

	write_string_table();

        fflush( obj_fd );
        fclose( obj_fd );

        delete_temp_files();
        return( 0 );
    }
    else
    {
        asm_exit( FATAL );
    }
}
Example #7
0
int
main(int argc,char **argv)
{
	int i;
	char* file = NULL;
	char* line = NULL;
	int   execute = 0;

	init_signal();

	o_stream = stdout;
	
	while((i = getopt_long(argc, argv, "svhxo:", long_options, NULL)) > 0)
	{
		switch(i)
		{
			case 's':
				suppress_error = 1;
				break;
			case 'v':
				die(VPRINT);
			case 'o':
				file = strdup(optarg);
				break;
			case 'x':
				execute = 1;
				break;
			case '?':
			case 'h':
			default:
				die(USAGE,argv[0]);
				break;
		}
	}

	banner();

	if(optind >= argc)
		die(USAGE,argv[0]);

	if(!(i_stream = fopen(argv[optind],"r")))
		xdie("fopen");

	i_file = argv[optind];

	if(file && !(o_stream = fopen(file,"w")))
		xdie("fopen");

	if(o_stream != stdout)
	{
		printf("Output redirected to %s...\n",file);

		close(1);
		if(dup(fileno(o_stream)) < 0)
			xdie("dup");
	}

	hexmne.symbols = malloc(sizeof(struct hexmne_sym));
	hexmne.syms_len = 1;

	hexmne.symbols[0].name = strdup("$$");
	hexmne.symbols[0].offset = 0;

	line = xmalloc(256);
	hexmne.instr = xmalloc(sizeof(struct hexmne_instr));
	hexmne.instr_len = i = 0;

	while(fgets(line,256,i_stream))
	{
		line[strlen(line)-1] = '\0';

#ifdef _DEBUG
		printf("[DEBUG]  %d:%s\n",nline,line);
#endif

		if(line[0] == '#' || line[0] == '\0')
			continue;

		if(stroff(line,'#') != -1)
			line[stroff(line,'#')] = '\0';

		if(line[0] == '@')
		{
			hexmne_preprocess( line );
			continue;
		}

		hexmne_parse_all( line );
	}

#ifdef _DEBUG
	dump_symbols();
#endif

	relocateAllSymbols();

	putchar('\n');

	printInstr();

	if(execute)
		lxs_execute();
	
	free(hexmne.symbols);
	free(hexmne.instr);
	free(line);

	if(file)
		free(file);

	if(o_stream != stdout)
		fclose(o_stream);

	return 0;
}