Top Level Namespace

Defined Under Namespace

Modules: LLDB Classes: WeakRef

Instance Method Summary collapse

Instance Method Details

#api_capability_probe(compiler, candidate, header, expression) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'ext/lldb/extconf.rb', line 99

def api_capability_probe(compiler, candidate, header, expression)
  source = <<~CPP
    #include <lldb/API/#{header}>

    int main() {
      auto method = #{expression};
      (void)method;
      return 0;
    }
  CPP

  _stdout, _stderr, status = native_probe(
    compiler,
    candidate.include_dir,
    candidate.lib_dir,
    source,
    link: false
  )
  status.success?
end

#lldb_library_present?(lib_dir) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'ext/lldb/extconf.rb', line 43

def lldb_library_present?(lib_dir)
  return false unless lib_dir && File.directory?(lib_dir)

  Dir.glob(File.join(lib_dir, 'liblldb.{so,dylib}*')).any?
end

#lldb_probe(compiler, candidate) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'ext/lldb/extconf.rb', line 49

def lldb_probe(compiler, candidate)
  return [false, 'include directory does not exist'] unless File.directory?(candidate.include_dir)
  return [false, 'library directory does not contain liblldb'] unless lldb_library_present?(candidate.lib_dir)

  source = <<~CPP
    #include <lldb/API/LLDB.h>

    int main() {
      lldb::SBDebugger debugger;
      return debugger.IsValid() ? 0 : 0;
    }
  CPP

  stdout, stderr, status = native_probe(
    compiler,
    candidate.include_dir,
    candidate.lib_dir,
    source,
    link: true
  )
  return [true, nil] if status.success?

  [false, [stdout, stderr].reject(&:empty?).join("\n")]
end

#llvm_config_version(candidate) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
# File 'ext/lldb/extconf.rb', line 120

def llvm_config_version(candidate)
  llvm_config = candidate.llvm_config
  if !llvm_config
    possible = File.join(candidate.lib_dir.to_s, '..', 'bin', 'llvm-config')
    llvm_config = possible if File.executable?(possible)
  end
  return 'unknown' unless llvm_config

  stdout, _stderr, status = run_command(llvm_config, '--version')
  status.success? && !stdout.strip.empty? ? stdout.strip : 'unknown'
end

#native_probe(compiler, include_dir, lib_dir, source, link:) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'ext/lldb/extconf.rb', line 24

def native_probe(compiler, include_dir, lib_dir, source, link:)
  Dir.mktmpdir('lldb-ruby-probe') do |directory|
    source_path = File.join(directory, 'probe.cpp')
    output_path = File.join(directory, 'probe')
    File.write(source_path, source)

    command = [*compiler, '-std=c++17', '-I', include_dir]
    if link
      command.concat([source_path, '-L', lib_dir, '-llldb', '-o', output_path])
      command << "-Wl,-rpath,#{lib_dir}"
      command << (RbConfig::CONFIG['host_os'] =~ /darwin/ ? '-lc++' : '-lstdc++')
    else
      command.concat(['-fsyntax-only', source_path])
    end

    run_command(*command)
  end
end

#run_command(*command) ⇒ Object



19
20
21
22
# File 'ext/lldb/extconf.rb', line 19

def run_command(*command)
  stdout, stderr, status = Open3.capture3(*command)
  [stdout, stderr, status]
end

#watchpoint_capability_probe(compiler, candidate) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'ext/lldb/extconf.rb', line 74

def watchpoint_capability_probe(compiler, candidate)
  source = <<~CPP
    #include <lldb/API/SBWatchpoint.h>

    int main() {
      auto reads = static_cast<bool (lldb::SBWatchpoint::*)()>(
        &lldb::SBWatchpoint::IsWatchingReads);
      auto writes = static_cast<bool (lldb::SBWatchpoint::*)()>(
        &lldb::SBWatchpoint::IsWatchingWrites);
      (void)reads;
      (void)writes;
      return 0;
    }
  CPP

  _stdout, _stderr, status = native_probe(
    compiler,
    candidate.include_dir,
    candidate.lib_dir,
    source,
    link: false
  )
  status.success?
end