Commit | Line | Data |
---|---|---|
5da83da5 AM |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013 Ericsson | |
3 | * | |
4 | * All rights reserved. This program and the accompanying materials are | |
5 | * made available under the terms of the Eclipse Public License v1.0 which | |
6 | * accompanies this distribution, and is available at | |
7 | * http://www.eclipse.org/legal/epl-v10.html | |
8 | * | |
9 | * Contributors: | |
10 | * Alexandre Montplaisir - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
13 | package org.eclipse.linuxtools.tmf.ui.views.callstack; | |
14 | ||
15 | import java.io.BufferedReader; | |
16 | import java.io.File; | |
17 | import java.io.FileNotFoundException; | |
18 | import java.io.FileReader; | |
19 | import java.io.IOException; | |
20 | import java.util.Collections; | |
21 | import java.util.HashMap; | |
22 | import java.util.Map; | |
23 | ||
24 | import org.eclipse.jdt.annotation.Nullable; | |
25 | ||
26 | /** | |
27 | * Class containing the different methods to import an address->name mapping. | |
28 | * | |
29 | * @author Alexandre Montplaisir | |
30 | */ | |
31 | class FunctionNameMapper { | |
32 | ||
33 | public static @Nullable Map<String, String> mapFromNmTextFile(File mappingFile) { | |
34 | Map<String, String> map = new HashMap<String, String>(); | |
35 | ||
36 | FileReader fr; | |
37 | try { | |
38 | fr = new FileReader(mappingFile); | |
39 | } catch (FileNotFoundException e) { | |
40 | return null; | |
41 | } | |
42 | BufferedReader reader = new BufferedReader(fr); | |
43 | ||
44 | try { | |
45 | for (String line = reader.readLine(); line != null; line = reader.readLine()) { | |
46 | String[] elems = line.split(" "); //$NON-NLS-1$ | |
47 | /* Only lines with 3 elements contain addresses */ | |
48 | if (elems.length == 3) { | |
49 | /* Strip the leading zeroes from the address */ | |
50 | String address = elems[0].replaceFirst("^0+(?!$)", ""); //$NON-NLS-1$ //$NON-NLS-2$; | |
51 | String name = elems[elems.length - 1]; | |
52 | map.put(address, name); | |
53 | } | |
54 | } | |
55 | ||
56 | } catch (IOException e) { | |
57 | /* Stop reading the file at this point */ | |
58 | } finally { | |
59 | try { | |
60 | reader.close(); | |
61 | } catch (IOException e) {} | |
62 | } | |
63 | ||
64 | if (map.isEmpty()) { | |
65 | return null; | |
66 | } | |
67 | return Collections.unmodifiableMap(map); | |
68 | } | |
69 | ||
70 | } |