Home | History | Annotate | Download | only in opjitconv
      1 /**
      2  * @file conversion.c
      3  * Convert a jit dump file to an ELF file
      4  *
      5  * @remark Copyright 2008 OProfile authors
      6  * @remark Read the file COPYING
      7  *
      8  * @author Daniel Hansel
      9  *
     10  * Copyright IBM Corporation 2008
     11  *
     12  */
     13 
     14 #include <stdlib.h>
     15 
     16 #include "opjitconv.h"
     17 
     18 static void free_jit_records(void)
     19 {
     20 	struct jitentry * entry, * next;
     21 
     22 	for (entry = jitentry_list; entry; entry = next) {
     23 		if (entry->sym_name_malloced)
     24 			free(entry->symbol_name);
     25 		next = entry->next;
     26 		free(entry);
     27 	}
     28 	jitentry_list = NULL;
     29 }
     30 
     31 static void free_jit_debug_line(void)
     32 {
     33 	struct jitentry_debug_line * entry, * next;
     34 
     35 	for (entry = jitentry_debug_line_list; entry; entry = next) {
     36 		next = entry->next;
     37 		free(entry);
     38 	}
     39 	jitentry_debug_line_list = NULL;
     40 }
     41 
     42 int op_jit_convert(struct op_jitdump_info file_info, char const * elffile,
     43                    unsigned long long start_time, unsigned long long end_time)
     44 {
     45 	void const * jitdump = file_info.dmp_file;
     46 	int rc= OP_JIT_CONV_OK;
     47 
     48 	entry_count = 0;
     49 	max_entry_count = 0;
     50 	syms = NULL;
     51 	cur_bfd = NULL;
     52 	jitentry_list = NULL;
     53 	jitentry_debug_line_list = NULL;
     54 	entries_symbols_ascending = entries_address_ascending = NULL;
     55 
     56 	if ((rc = parse_all(jitdump, jitdump + file_info.dmp_file_stat.st_size,
     57 	                    end_time)) == OP_JIT_CONV_FAIL)
     58 		goto out;
     59 
     60 	create_arrays();
     61 	if ((rc = resolve_overlaps(start_time)) == OP_JIT_CONV_FAIL)
     62 		goto out;
     63 
     64 	disambiguate_symbol_names();
     65 	if (!entry_count)
     66 		return OP_JIT_CONV_NO_JIT_RECS_IN_DUMPFILE;
     67 
     68 	if ((cur_bfd = open_elf(elffile)) == NULL) {
     69 		rc = OP_JIT_CONV_FAIL;
     70 		goto out;
     71 	}
     72 
     73 	init_debug_line_info(cur_bfd);
     74 
     75 	if ((rc = partition_sections()) == OP_JIT_CONV_FAIL)
     76 		goto out;
     77 
     78 	if ((rc = fill_sections()) == OP_JIT_CONV_FAIL)
     79 		goto out;
     80 
     81 	finalize_debug_line_info(cur_bfd);
     82 
     83 	if (cur_bfd)
     84 		bfd_close(cur_bfd);
     85 	free(syms);
     86 	out: free_jit_records();
     87 	free_jit_debug_line();
     88 	free(entries_symbols_ascending);
     89 	free(entries_address_ascending);
     90 	return rc;
     91 }
     92 
     93