aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/host
diff options
context:
space:
mode:
authorJoey Jiao <joeyjiaojg@gmail.com>2021-03-02 09:31:32 +0800
committerDmitry Vyukov <dvyukov@google.com>2021-03-18 09:17:51 +0100
commit5e933e8c7b82e170b667885d3b99098e2e86f29d (patch)
tree296f3795fcafa6b37b040d985da97cb3bd13142b /pkg/host
parentfdb2bb2c23ee709880407f56307e2800ad27e9ae (diff)
all: support coverage of kernel modules
The PCs returned for dynamic loaded module (DLKM) is not parsed in coverage page, these PCs are dropped. The commit is to use DLKM modules' load address and symbol file to restore the PC and show coverage data of DLKM. Introduced new config module_obj to specify module directories. Example of config: "module_obj": [ "module_path1" "module_path2" ] For linux target, before Manager.Connect run, load addresses are getting from /proc/modules in order to group PCs into modules. And so, if modules are under kernel_obj or module_obj dir, their addresses and paths can be generated automatically. kernel_obj is searched before module_obj dir and the first found ko object is always used. Also note that kaslr needs to be disabled.
Diffstat (limited to 'pkg/host')
-rw-r--r--pkg/host/machine_info.go10
-rw-r--r--pkg/host/machine_info_linux.go20
-rw-r--r--pkg/host/machine_info_linux_test.go8
3 files changed, 38 insertions, 0 deletions
diff --git a/pkg/host/machine_info.go b/pkg/host/machine_info.go
index 7a7cd2612..8bd706a15 100644
--- a/pkg/host/machine_info.go
+++ b/pkg/host/machine_info.go
@@ -26,9 +26,19 @@ func CollectMachineInfo() ([]byte, error) {
return buf.Bytes(), nil
}
+func CollectModulesInfo() ([]KernelModule, error) {
+ return machineModulesInfo()
+}
+
var machineInfoFuncs []machineInfoFunc
+var machineModulesInfo func() ([]KernelModule, error)
type machineInfoFunc struct {
name string
fn func(*bytes.Buffer) error
}
+
+type KernelModule struct {
+ Name string
+ Addr uint64
+}
diff --git a/pkg/host/machine_info_linux.go b/pkg/host/machine_info_linux.go
index da1ee481a..eab2a1810 100644
--- a/pkg/host/machine_info_linux.go
+++ b/pkg/host/machine_info_linux.go
@@ -10,6 +10,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
+ "regexp"
"strings"
)
@@ -18,6 +19,7 @@ func init() {
{"CPU Info", readCPUInfo},
{"KVM", readKVMInfo},
}
+ machineModulesInfo = getModulesInfo
}
func readCPUInfo(buffer *bytes.Buffer) error {
@@ -120,3 +122,21 @@ func readKVMInfo(buffer *bytes.Buffer) error {
}
return nil
}
+
+func getModulesInfo() ([]KernelModule, error) {
+ var addr uint64
+ var modules []KernelModule
+ modulesText, _ := ioutil.ReadFile("/proc/modules")
+ re := regexp.MustCompile(`(\w+) .*(0[x|X][a-fA-F0-9]+)[^\n]*`)
+ matches := re.FindAllSubmatch(modulesText, -1)
+ for _, m := range matches {
+ if _, err := fmt.Sscanf(strings.TrimPrefix(strings.ToLower(string(m[2])), "0x"), "%x", &addr); err != nil {
+ return nil, fmt.Errorf("address parsing error in /proc/modules")
+ }
+ modules = append(modules, KernelModule{
+ Name: string(m[1]),
+ Addr: addr,
+ })
+ }
+ return modules, nil
+}
diff --git a/pkg/host/machine_info_linux_test.go b/pkg/host/machine_info_linux_test.go
index 5075751d5..87ebbf025 100644
--- a/pkg/host/machine_info_linux_test.go
+++ b/pkg/host/machine_info_linux_test.go
@@ -143,6 +143,14 @@ D: d
}
}
+func TestGetModulesInfo(t *testing.T) {
+ modules, err := getModulesInfo()
+ if err != nil {
+ t.Fatal(err)
+ }
+ t.Logf("modules:\n%v", modules)
+}
+
type cannedTest struct {
arch string
data string