@@ -2045,17 +2045,14 @@ static char *expand_tabs(char *line, char **storage, size_t *storage_len)
2045
2045
return new_line ;
2046
2046
}
2047
2047
2048
- int symbol__disassemble (struct symbol * sym , struct annotate_args * args )
2048
+ static int symbol__disassemble_objdump (const char * filename , struct symbol * sym ,
2049
+ struct annotate_args * args )
2049
2050
{
2050
2051
struct annotation_options * opts = & annotate_opts ;
2051
2052
struct map * map = args -> ms .map ;
2052
2053
struct dso * dso = map__dso (map );
2053
2054
char * command ;
2054
2055
FILE * file ;
2055
- char symfs_filename [PATH_MAX ];
2056
- struct kcore_extract kce ;
2057
- bool delete_extract = false;
2058
- bool decomp = false;
2059
2056
int lineno = 0 ;
2060
2057
char * fileloc = NULL ;
2061
2058
int nline ;
@@ -2070,77 +2067,7 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
2070
2067
NULL ,
2071
2068
};
2072
2069
struct child_process objdump_process ;
2073
- int err = dso__disassemble_filename (dso , symfs_filename , sizeof (symfs_filename ));
2074
-
2075
- if (err )
2076
- return err ;
2077
-
2078
- pr_debug ("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n" , __func__ ,
2079
- symfs_filename , sym -> name , map__unmap_ip (map , sym -> start ),
2080
- map__unmap_ip (map , sym -> end ));
2081
-
2082
- pr_debug ("annotating [%p] %30s : [%p] %30s\n" ,
2083
- dso , dso__long_name (dso ), sym , sym -> name );
2084
-
2085
- if (dso__binary_type (dso ) == DSO_BINARY_TYPE__BPF_PROG_INFO ) {
2086
- return symbol__disassemble_bpf (sym , args );
2087
- } else if (dso__binary_type (dso ) == DSO_BINARY_TYPE__BPF_IMAGE ) {
2088
- return symbol__disassemble_bpf_image (sym , args );
2089
- } else if (dso__binary_type (dso ) == DSO_BINARY_TYPE__NOT_FOUND ) {
2090
- return -1 ;
2091
- } else if (dso__is_kcore (dso )) {
2092
- kce .kcore_filename = symfs_filename ;
2093
- kce .addr = map__rip_2objdump (map , sym -> start );
2094
- kce .offs = sym -> start ;
2095
- kce .len = sym -> end - sym -> start ;
2096
- if (!kcore_extract__create (& kce )) {
2097
- delete_extract = true;
2098
- strlcpy (symfs_filename , kce .extract_filename ,
2099
- sizeof (symfs_filename ));
2100
- }
2101
- } else if (dso__needs_decompress (dso )) {
2102
- char tmp [KMOD_DECOMP_LEN ];
2103
-
2104
- if (dso__decompress_kmodule_path (dso , symfs_filename ,
2105
- tmp , sizeof (tmp )) < 0 )
2106
- return -1 ;
2107
-
2108
- decomp = true;
2109
- strcpy (symfs_filename , tmp );
2110
- }
2111
-
2112
- /*
2113
- * For powerpc data type profiling, use the dso__data_read_offset
2114
- * to read raw instruction directly and interpret the binary code
2115
- * to understand instructions and register fields. For sort keys as
2116
- * type and typeoff, disassemble to mnemonic notation is
2117
- * not required in case of powerpc.
2118
- */
2119
- if (arch__is (args -> arch , "powerpc" )) {
2120
- extern const char * sort_order ;
2121
-
2122
- if (sort_order && !strstr (sort_order , "sym" )) {
2123
- err = symbol__disassemble_raw (symfs_filename , sym , args );
2124
- if (err == 0 )
2125
- goto out_remove_tmp ;
2126
- #ifdef HAVE_LIBCAPSTONE_SUPPORT
2127
- err = symbol__disassemble_capstone_powerpc (symfs_filename , sym , args );
2128
- if (err == 0 )
2129
- goto out_remove_tmp ;
2130
- #endif
2131
- }
2132
- }
2133
-
2134
- #ifdef HAVE_LIBLLVM_SUPPORT
2135
- err = symbol__disassemble_llvm (symfs_filename , sym , args );
2136
- if (err == 0 )
2137
- goto out_remove_tmp ;
2138
- #endif
2139
- #ifdef HAVE_LIBCAPSTONE_SUPPORT
2140
- err = symbol__disassemble_capstone (symfs_filename , sym , args );
2141
- if (err == 0 )
2142
- goto out_remove_tmp ;
2143
- #endif
2070
+ int err ;
2144
2071
2145
2072
err = asprintf (& command ,
2146
2073
"%s %s%s --start-address=0x%016" PRIx64
@@ -2163,13 +2090,13 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
2163
2090
2164
2091
if (err < 0 ) {
2165
2092
pr_err ("Failure allocating memory for the command to run\n" );
2166
- goto out_remove_tmp ;
2093
+ return err ;
2167
2094
}
2168
2095
2169
2096
pr_debug ("Executing: %s\n" , command );
2170
2097
2171
2098
objdump_argv [2 ] = command ;
2172
- objdump_argv [4 ] = symfs_filename ;
2099
+ objdump_argv [4 ] = filename ;
2173
2100
2174
2101
/* Create a pipe to read from for stdout */
2175
2102
memset (& objdump_process , 0 , sizeof (objdump_process ));
@@ -2207,8 +2134,8 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
2207
2134
break ;
2208
2135
2209
2136
/* Skip lines containing "filename:" */
2210
- match = strstr (line , symfs_filename );
2211
- if (match && match [strlen (symfs_filename )] == ':' )
2137
+ match = strstr (line , filename );
2138
+ if (match && match [strlen (filename )] == ':' )
2212
2139
continue ;
2213
2140
2214
2141
expanded_line = strim (line );
@@ -2253,6 +2180,87 @@ int symbol__disassemble(struct symbol *sym, struct annotate_args *args)
2253
2180
2254
2181
out_free_command :
2255
2182
free (command );
2183
+ return err ;
2184
+ }
2185
+
2186
+ int symbol__disassemble (struct symbol * sym , struct annotate_args * args )
2187
+ {
2188
+ struct map * map = args -> ms .map ;
2189
+ struct dso * dso = map__dso (map );
2190
+ char symfs_filename [PATH_MAX ];
2191
+ bool delete_extract = false;
2192
+ struct kcore_extract kce ;
2193
+ bool decomp = false;
2194
+ int err = dso__disassemble_filename (dso , symfs_filename , sizeof (symfs_filename ));
2195
+
2196
+ if (err )
2197
+ return err ;
2198
+
2199
+ pr_debug ("%s: filename=%s, sym=%s, start=%#" PRIx64 ", end=%#" PRIx64 "\n" , __func__ ,
2200
+ symfs_filename , sym -> name , map__unmap_ip (map , sym -> start ),
2201
+ map__unmap_ip (map , sym -> end ));
2202
+
2203
+ pr_debug ("annotating [%p] %30s : [%p] %30s\n" , dso , dso__long_name (dso ), sym , sym -> name );
2204
+
2205
+ if (dso__binary_type (dso ) == DSO_BINARY_TYPE__BPF_PROG_INFO ) {
2206
+ return symbol__disassemble_bpf (sym , args );
2207
+ } else if (dso__binary_type (dso ) == DSO_BINARY_TYPE__BPF_IMAGE ) {
2208
+ return symbol__disassemble_bpf_image (sym , args );
2209
+ } else if (dso__binary_type (dso ) == DSO_BINARY_TYPE__NOT_FOUND ) {
2210
+ return -1 ;
2211
+ } else if (dso__is_kcore (dso )) {
2212
+ kce .addr = map__rip_2objdump (map , sym -> start );
2213
+ kce .kcore_filename = symfs_filename ;
2214
+ kce .len = sym -> end - sym -> start ;
2215
+ kce .offs = sym -> start ;
2216
+
2217
+ if (!kcore_extract__create (& kce )) {
2218
+ delete_extract = true;
2219
+ strlcpy (symfs_filename , kce .extract_filename , sizeof (symfs_filename ));
2220
+ }
2221
+ } else if (dso__needs_decompress (dso )) {
2222
+ char tmp [KMOD_DECOMP_LEN ];
2223
+
2224
+ if (dso__decompress_kmodule_path (dso , symfs_filename , tmp , sizeof (tmp )) < 0 )
2225
+ return -1 ;
2226
+
2227
+ decomp = true;
2228
+ strcpy (symfs_filename , tmp );
2229
+ }
2230
+
2231
+ /*
2232
+ * For powerpc data type profiling, use the dso__data_read_offset to
2233
+ * read raw instruction directly and interpret the binary code to
2234
+ * understand instructions and register fields. For sort keys as type
2235
+ * and typeoff, disassemble to mnemonic notation is not required in
2236
+ * case of powerpc.
2237
+ */
2238
+ if (arch__is (args -> arch , "powerpc" )) {
2239
+ extern const char * sort_order ;
2240
+
2241
+ if (sort_order && !strstr (sort_order , "sym" )) {
2242
+ err = symbol__disassemble_raw (symfs_filename , sym , args );
2243
+ if (err == 0 )
2244
+ goto out_remove_tmp ;
2245
+ #ifdef HAVE_LIBCAPSTONE_SUPPORT
2246
+ err = symbol__disassemble_capstone_powerpc (symfs_filename , sym , args );
2247
+ if (err == 0 )
2248
+ goto out_remove_tmp ;
2249
+ #endif
2250
+ }
2251
+ }
2252
+
2253
+ #ifdef HAVE_LIBLLVM_SUPPORT
2254
+ err = symbol__disassemble_llvm (symfs_filename , sym , args );
2255
+ if (err == 0 )
2256
+ goto out_remove_tmp ;
2257
+ #endif
2258
+ #ifdef HAVE_LIBCAPSTONE_SUPPORT
2259
+ err = symbol__disassemble_capstone (symfs_filename , sym , args );
2260
+ if (err == 0 )
2261
+ goto out_remove_tmp ;
2262
+ #endif
2263
+ err = symbol__disassemble_objdump (symfs_filename , sym , args );
2256
2264
2257
2265
out_remove_tmp :
2258
2266
if (decomp )
0 commit comments