Class: Tracetool::Android::NativeTraceScanner

Inherits:
Object
  • Object
show all
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('*', '\*')}/.freeze
RX_PC_ADDRESS =

Contains address line like

“‘ pc 00000000004321ec libfoo.so “`

/pc \d+/.freeze
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]+ [^ ]+ (.+)?;)+>>>)+$/.freeze

Constants included from NativeTraceEnhancer

Tracetool::Android::NativeTraceEnhancer::NATIVE_DUMP_HEADER

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NativeTraceEnhancer

add_header, unpack

Constructor Details

#initialize(string) ⇒ NativeTraceScanner

Returns a new instance of NativeTraceScanner.

Parameters:

  • string (String)

    well formed native android stack trace

See Also:



100
101
102
# File 'lib/tracetool/android/native.rb', line 100

def initialize(string)
  @trace = string
end

Class Method Details

.[](string) ⇒ NativeTraceScanner

With given potential stack trace string create scanner if possible

Parameters:

Returns:



148
149
150
151
152
153
154
155
156
# File 'lib/tracetool/android/native.rb', line 148

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

Returns:

  • (Boolean)


134
135
136
137
138
# File 'lib/tracetool/android/native.rb', line 134

def address_lines?(lines)
  lines.all? do |line|
    RX_PC_ADDRESS.match(line)
  end
end

.packed?(string) ⇒ Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/tracetool/android/native.rb', line 122

def packed?(string)
  RX_PACKED_FORMAT.match(string)
end

.with_header?(string) ⇒ Boolean

Returns:

  • (Boolean)


140
141
142
# File 'lib/tracetool/android/native.rb', line 140

def with_header?(string)
  RX_INITIAL_ASTERISKS.match(string)
end

.without_header?(string) ⇒ Boolean

Returns:

  • (Boolean)


126
127
128
129
130
131
132
# File 'lib/tracetool/android/native.rb', line 126

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

Parameters:

  • files (Array)

    list of files used in build. This files are used to match file entries from stack trace to real files

Returns:



115
116
117
# File 'lib/tracetool/android/native.rb', line 115

def parser(files)
  NativeTraceParser.new(files)
end

#process(ctx) ⇒ String

Returns desymbolicated stack trace.

Parameters:

  • ctx (OpenStruct)

    context object containing ‘symbols` field with path to symbols dir

Returns:

  • (String)

    desymbolicated stack trace



107
108
109
# File 'lib/tracetool/android/native.rb', line 107

def process(ctx)
  Pipe['ndk-stack', '-sym', ctx.symbols] << @trace
end