1 /* 2 * Copyright (C) 2007 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.ddmlib; 18 19 import java.util.regex.Matcher; 20 import java.util.regex.Pattern; 21 22 /** 23 * Represents a stack call. This is used to return all of the call 24 * information as one object. 25 */ 26 public final class NativeStackCallInfo { 27 private final static Pattern SOURCE_NAME_PATTERN = Pattern.compile("^(.+):(\\d+)$"); 28 29 /** name of the library */ 30 private String mLibrary; 31 32 /** name of the method */ 33 private String mMethod; 34 35 /** 36 * name of the source file + line number in the format<br> 37 * <sourcefile>:<linenumber> 38 */ 39 private String mSourceFile; 40 41 private int mLineNumber = -1; 42 43 /** 44 * Basic constructor with library, method, and sourcefile information 45 * 46 * @param lib The name of the library 47 * @param method the name of the method 48 * @param sourceFile the name of the source file and the line number 49 * as "[sourcefile]:[fileNumber]" 50 */ NativeStackCallInfo(String lib, String method, String sourceFile)51 public NativeStackCallInfo(String lib, String method, String sourceFile) { 52 mLibrary = lib; 53 mMethod = method; 54 55 Matcher m = SOURCE_NAME_PATTERN.matcher(sourceFile); 56 if (m.matches()) { 57 mSourceFile = m.group(1); 58 try { 59 mLineNumber = Integer.parseInt(m.group(2)); 60 } catch (NumberFormatException e) { 61 // do nothing, the line number will stay at -1 62 } 63 } else { 64 mSourceFile = sourceFile; 65 } 66 } 67 68 /** 69 * Returns the name of the library name. 70 */ getLibraryName()71 public String getLibraryName() { 72 return mLibrary; 73 } 74 75 /** 76 * Returns the name of the method. 77 */ getMethodName()78 public String getMethodName() { 79 return mMethod; 80 } 81 82 /** 83 * Returns the name of the source file. 84 */ getSourceFile()85 public String getSourceFile() { 86 return mSourceFile; 87 } 88 89 /** 90 * Returns the line number, or -1 if unknown. 91 */ getLineNumber()92 public int getLineNumber() { 93 return mLineNumber; 94 } 95 } 96