Class: Tracetool::Android::NativeTraceScanner
- Inherits:
-
Object
- Object
- Tracetool::Android::NativeTraceScanner
- Extended by:
- NativeTraceEnhancer
- Defined in:
- lib/tracetool/android/native.rb
Overview
Processes native traces
Constant Summary collapse
- TRACE_DELIMETER =
Initial sequence of asterisks which marks begining of trace body
'*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***'.freeze
- RX_INITIAL_ASTERISKS =
/#{TRACE_DELIMETER.gsub('*', '\*')}/- RX_PC_ADDRESS =
Contains address line like
“‘ pc 00000000004321ec libfoo.so “`
/pc \d+/- RX_PACKED_FORMAT =
Format of packed trace. Consists of one or more trace blocks.
-
Each block starts with ‘<<<` and ends with `>>>`.
-
Each block contains one or more lines
-
Lines delimited with ;
-
Line consists of
** pointer address ‘/d+/` ** library (so) name `/[^ ]+/` ** symbol name `/[^ ]+/`, if present ** symbol offset `/d+/`
Last two entries can be missing.
-
/^(<<<(\d+ [^ ]+ ([^ ]+ \d+)?;)+>>>)+$/
Constants included from NativeTraceEnhancer
Tracetool::Android::NativeTraceEnhancer::NATIVE_DUMP_HEADER
Class Method Summary collapse
-
.[](string) ⇒ NativeTraceScanner
With given potential stack trace string create scanner if possible.
- .address_lines?(lines) ⇒ Boolean
- .packed?(string) ⇒ Boolean
- .with_header?(string) ⇒ Boolean
- .without_header?(string) ⇒ Boolean
Instance Method Summary collapse
-
#initialize(string) ⇒ NativeTraceScanner
constructor
A new instance of NativeTraceScanner.
-
#parser(files) ⇒ Tracetool::BaseTraceParser
Create parser for current trace format.
-
#process(ctx) ⇒ String
Desymbolicated stack trace.
Methods included from NativeTraceEnhancer
Constructor Details
#initialize(string) ⇒ NativeTraceScanner
Returns a new instance of NativeTraceScanner.
91 92 93 |
# File 'lib/tracetool/android/native.rb', line 91 def initialize(string) @trace = string end |
Class Method Details
.[](string) ⇒ NativeTraceScanner
With given potential stack trace string create scanner if possible
145 146 147 148 149 150 151 152 153 |
# File 'lib/tracetool/android/native.rb', line 145 def [](string) if packed? string new(unpack(string)) elsif with_header? string new(string) elsif without_header? string new(add_header(string)) end end |
.address_lines?(lines) ⇒ Boolean
131 132 133 134 135 |
# File 'lib/tracetool/android/native.rb', line 131 def address_lines?(lines) lines.all? do |line| RX_PC_ADDRESS.match(line) end end |
.packed?(string) ⇒ Boolean
119 120 121 |
# File 'lib/tracetool/android/native.rb', line 119 def packed?(string) RX_PACKED_FORMAT.match(string) end |
.with_header?(string) ⇒ Boolean
137 138 139 |
# File 'lib/tracetool/android/native.rb', line 137 def with_header?(string) RX_INITIAL_ASTERISKS.match(string) end |
.without_header?(string) ⇒ Boolean
123 124 125 126 127 128 129 |
# File 'lib/tracetool/android/native.rb', line 123 def without_header?(string) lines = string.split("\n") return true if address_lines?(lines) first, *rest = lines first.include?('backtrace:') && address_lines?(rest) end |
Instance Method Details
#parser(files) ⇒ Tracetool::BaseTraceParser
Create parser for current trace format
112 113 114 |
# File 'lib/tracetool/android/native.rb', line 112 def parser(files) NativeTraceParser.new(files) end |
#process(ctx) ⇒ String
Returns desymbolicated stack trace.
98 99 100 101 102 103 104 105 106 |
# File 'lib/tracetool/android/native.rb', line 98 def process(ctx) symbols = File.join(ctx.symbols, 'local') symbols = if ctx.arch File.join(symbols, ctx.arch) else Dir[File.join(symbols, '*')].first || symbols end Pipe['ndk-stack', '-sym', symbols] << @trace end |