Home | History | Annotate | Download | only in heap
      1 /*
      2  * Copyright (C) 2011 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.ddmuilib.heap;
     18 
     19 import com.android.ddmlib.NativeStackCallInfo;
     20 
     21 import org.eclipse.jface.viewers.ITableLabelProvider;
     22 import org.eclipse.jface.viewers.LabelProvider;
     23 import org.eclipse.swt.graphics.Image;
     24 
     25 public class NativeStackLabelProvider extends LabelProvider implements ITableLabelProvider {
     26     public Image getColumnImage(Object arg0, int arg1) {
     27         return null;
     28     }
     29 
     30     public String getColumnText(Object element, int index) {
     31         if (element instanceof NativeStackCallInfo) {
     32             return getResolvedStackTraceColumnText((NativeStackCallInfo) element, index);
     33         }
     34 
     35         if (element instanceof Long) {
     36             // if the addresses have not been resolved, then just display the
     37             // addresses alone
     38             return getStackAddressColumnText((Long) element, index);
     39         }
     40 
     41         return null;
     42     }
     43 
     44     public String getResolvedStackTraceColumnText(NativeStackCallInfo info, int index) {
     45         switch (index) {
     46         case 0:
     47             return String.format("0x%08x", info.getAddress());
     48         case 1:
     49             return info.getLibraryName();
     50         case 2:
     51             return info.getMethodName();
     52         case 3:
     53             return info.getSourceFile();
     54         case 4:
     55             int l = info.getLineNumber();
     56             return l == -1 ? "" : Integer.toString(l);
     57         }
     58 
     59         return null;
     60     }
     61 
     62     private String getStackAddressColumnText(Long address, int index) {
     63         if (index == 0) {
     64             return String.format("0x%08x", address);
     65         }
     66 
     67         return null;
     68     }
     69 }
     70