|
1 /* |
|
2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * |
|
5 * Redistribution and use in source and binary forms, with or without |
|
6 * modification, are permitted provided that the following conditions are met: |
|
7 * |
|
8 * - Redistributions of source code must retain the above copyright notice, |
|
9 * this list of conditions and the following disclaimer. |
|
10 * - Redistributions in binary form must reproduce the above copyright notice, |
|
11 * this list of conditions and the following disclaimer in the documentation |
|
12 * and/or other materials provided with the distribution. |
|
13 * - Neither the name of Nokia Corporation nor the names of its contributors |
|
14 * may be used to endorse or promote products derived from this software |
|
15 * without specific prior written permission. |
|
16 * |
|
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
27 * POSSIBILITY OF SUCH DAMAGE. |
|
28 * |
|
29 * Initial Contributors: |
|
30 * Nokia Corporation - initial contribution. |
|
31 * |
|
32 * Contributors: |
|
33 * |
|
34 * Description: |
|
35 * |
|
36 */ |
|
37 |
|
38 using System; |
|
39 using System.Drawing; |
|
40 using System.Collections; |
|
41 using System.Collections.Generic; |
|
42 using System.ComponentModel; |
|
43 using System.Windows.Forms; |
|
44 using System.Text; |
|
45 using SymbianUtils; |
|
46 using HeapLib; |
|
47 using HeapLib.Cells; |
|
48 using HeapLib.Array; |
|
49 using HeapLib.Relationships; |
|
50 using HeapLib.Reconstructor; |
|
51 using HeapLib.Statistics.Tracking.Base; |
|
52 using HeapLib.Statistics.Tracking.BySymbol; |
|
53 using HeapLib.Reconstructor.DataSources; |
|
54 |
|
55 namespace HeapUiLib.Controls |
|
56 { |
|
57 public partial class HeapCellInfoControl : UserControl |
|
58 { |
|
59 #region Constructors & destructor |
|
60 public HeapCellInfoControl() |
|
61 { |
|
62 InitializeComponent(); |
|
63 } |
|
64 #endregion |
|
65 |
|
66 #region Properties |
|
67 public bool ShowStackBasedFunctionAddresses |
|
68 { |
|
69 get { return iShowStackBasedFunctionAddresses; } |
|
70 set |
|
71 { |
|
72 iShowStackBasedFunctionAddresses = value; |
|
73 if ( value ) |
|
74 { |
|
75 iLVInfoCellHeader.Items[ 3 ].Text = "Symbol #1"; |
|
76 iLVInfoCellHeader.Items[ 4 ].Text = "Symbol #2"; |
|
77 } |
|
78 else |
|
79 { |
|
80 iLVInfoCellHeader.Items[ 3 ].Text = "Nesting level"; |
|
81 iLVInfoCellHeader.Items[ 4 ].Text = "Allocation #"; |
|
82 } |
|
83 } |
|
84 } |
|
85 |
|
86 public HeapCell Cell |
|
87 { |
|
88 set |
|
89 { |
|
90 if ( value != null ) |
|
91 { |
|
92 UpdateInfoHeaderListView( value ); |
|
93 UpdateInfoPayloadListView( value ); |
|
94 } |
|
95 } |
|
96 } |
|
97 #endregion |
|
98 |
|
99 #region Internal methods |
|
100 private void UpdateInfoHeaderListView( HeapCell aCell ) |
|
101 { |
|
102 // Address |
|
103 iLVInfoCellHeader.Items[ 0 ].SubItems[ 1 ].Text = "0x" + aCell.Address.ToString( "x8" ); |
|
104 |
|
105 // Payload address |
|
106 iLVInfoCellHeader.Items[ 1 ].SubItems[ 1 ].Text = "0x" + aCell.StartOfPayloadAddress.ToString( "x8" ) + " -> 0x" + aCell.EndAddress.ToString( "x8" ); |
|
107 |
|
108 // Length |
|
109 iLVInfoCellHeader.Items[ 2 ].SubItems[ 1 ].Text = aCell.Length.ToString(); |
|
110 |
|
111 // Nesting level |
|
112 string nestingLevel = "N/A (Release EUSER)"; |
|
113 if ( aCell.Type == HeapCell.TType.EFree ) |
|
114 { |
|
115 nestingLevel = "N/A (Free Cell)"; |
|
116 } |
|
117 else if ( ShowStackBasedFunctionAddresses ) |
|
118 { |
|
119 nestingLevel = "Unknown"; |
|
120 if ( aCell.Symbol2 != null ) |
|
121 { |
|
122 nestingLevel = aCell.Symbol2.Address.ToString( "x8" ) + " " + aCell.Symbol2.Name; |
|
123 } |
|
124 } |
|
125 else if ( HeapCell.IsDebugAllocator ) |
|
126 { |
|
127 nestingLevel = aCell.NestingLevel.ToString(); |
|
128 } |
|
129 iLVInfoCellHeader.Items[ 3 ].SubItems[ 1 ].Text = nestingLevel; |
|
130 |
|
131 // Allocation # |
|
132 string allocNumber = "N/A (Release EUSER)"; |
|
133 if ( aCell.Type == HeapCell.TType.EFree ) |
|
134 { |
|
135 allocNumber = "N/A (Free Cell)"; |
|
136 } |
|
137 else if ( ShowStackBasedFunctionAddresses ) |
|
138 { |
|
139 allocNumber = "Unknown"; |
|
140 if ( aCell.Symbol3 != null ) |
|
141 { |
|
142 allocNumber = aCell.Symbol3.Address.ToString( "x8" ) + " " + aCell.Symbol3.Name; |
|
143 } |
|
144 } |
|
145 else if ( HeapCell.IsDebugAllocator ) |
|
146 { |
|
147 allocNumber = aCell.AllocationNumber.ToString(); |
|
148 } |
|
149 iLVInfoCellHeader.Items[ 4 ].SubItems[ 1 ].Text = allocNumber; |
|
150 } |
|
151 |
|
152 private void UpdateInfoPayloadListView( HeapCell aCell ) |
|
153 { |
|
154 // Length |
|
155 iLVInfoCellPayload.Items[ 0 ].SubItems[ 1 ].Text = aCell.PayloadLength.ToString(); |
|
156 |
|
157 // Symbol |
|
158 if ( aCell.Symbol != null ) |
|
159 { |
|
160 iLVInfoCellPayload.Items[ 1 ].SubItems[ 1 ].Text = aCell.Symbol.NameWithoutVTablePrefix; |
|
161 } |
|
162 else if ( aCell.Type == HeapCell.TType.EFree ) |
|
163 { |
|
164 iLVInfoCellPayload.Items[ 1 ].SubItems[ 1 ].Text = "N/A (Free Cell)"; |
|
165 } |
|
166 else |
|
167 { |
|
168 iLVInfoCellPayload.Items[ 1 ].SubItems[ 1 ].Text = "???"; |
|
169 } |
|
170 } |
|
171 #endregion |
|
172 |
|
173 #region Event handlers |
|
174 private void HeapCellInfoControl_SizeChanged( object sender, EventArgs e ) |
|
175 { |
|
176 int col1Width = iLVInfoCellHeader.Columns[ 0 ].Width; |
|
177 int col2Width = iLVInfoCellHeader.Columns[ 1 ].Width; |
|
178 int width = iLVInfoCellHeader.Width; |
|
179 iLVInfoCellHeader.Columns[ 1 ].Width = width - col1Width; |
|
180 } |
|
181 |
|
182 private void iLVInfoCellHeader_KeyDown( object sender, KeyEventArgs e ) |
|
183 { |
|
184 bool wasControl = ( e.Modifiers & Keys.Control ) == Keys.Control; |
|
185 if ( wasControl && ( e.KeyCode == Keys.C ) ) |
|
186 { |
|
187 if ( iLVInfoCellHeader.SelectedItems != null && iLVInfoCellHeader.SelectedItems.Count > 0 ) |
|
188 { |
|
189 ListViewItem item = iLVInfoCellHeader.SelectedItems[ 0 ]; |
|
190 ListViewItem.ListViewSubItem infoItem = item.SubItems[ 1 ]; |
|
191 Clipboard.SetText( infoItem.Text.Trim() ); |
|
192 } |
|
193 } |
|
194 } |
|
195 #endregion |
|
196 |
|
197 #region Data members |
|
198 private bool iShowStackBasedFunctionAddresses = false; |
|
199 #endregion |
|
200 } |
|
201 } |