Skip to contentSkip to conversation

scripts: fix the sys path for gdb scripts

PATCH In review yalin wang 2 participants 3 messages Nov 27, 2015

Subsystems (2)
lore
Share & tools
lore

yalin wang

author
#0 lore raw

PATCH v2 1/1 scripts: fix the sys path for gdb scripts

we insert __file__'s real path into sys.path,
so that no matter we import the vmlinux-gdb.py from $OUT floder or from source code folder, we can always find the linux/ lib folder, and we don't need create link to linux/*.py files, remove the related make file.

---
 scripts/Makefile           |  1 -
 scripts/gdb/Makefile       |  1 -
 scripts/gdb/linux/Makefile | 11 -----------
 scripts/gdb/vmlinux-gdb.py |  2 +-
 4 files changed, 1 insertion(+), 14 deletions(-)
 delete mode 100644 scripts/gdb/Makefile
 delete mode 100644 scripts/gdb/linux/Makefile
scripts/Makefile +0 -1
index 2016a64..72902b5 100644
@@ -36,7 +36,6 @@ subdir-$(CONFIG_MODVERSIONS) += genksyms
 subdir-y                     += mod
 subdir-$(CONFIG_SECURITY_SELINUX) += selinux
 subdir-$(CONFIG_DTC)         += dtc
-subdir-$(CONFIG_GDB_SCRIPTS) += gdb
 
 # Let clean descend into subdirs
 subdir-	+= basic kconfig package
scripts/gdb/Makefile deleted +0 -1
deleted file mode 100644
index 62f5f65..0000000
@@ -1 +0,0 @@
-subdir-y := linux
scripts/gdb/linux/Makefile deleted +0 -11
deleted file mode 100644
index 6cf1ecf..0000000
@@ -1,11 +0,0 @@
-always := gdb-scripts
-
-SRCTREE := $(shell cd $(srctree) && /bin/pwd)
-
-$(obj)/gdb-scripts:
-ifneq ($(KBUILD_SRC),)
-	$(Q)ln -fsn $(SRCTREE)/$(obj)/*.py $(objtree)/$(obj)
-endif
-	@:
-
-clean-files := *.pyc *.pyo $(if $(KBUILD_SRC),*.py)
scripts/gdb/vmlinux-gdb.py +1 -1
index ce82bf5..a9029f4 100644
@@ -13,7 +13,7 @@
 
 import os
 
-sys.path.insert(0, os.path.dirname(__file__) + "/scripts/gdb")
+sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))
 
 try:
     gdb.parse_and_eval("0")
Signature · 1 line
1.9.1
maintainer
#1 lore raw
Quoted 5 lines · yalin wang

we insert __file__'s real path into sys.path,
so that no matter we import the vmlinux-gdb.py from $OUT floder or from source code folder, we can always find the linux/ lib folder, and we don't need create link to linux/*.py files, remove the related make file.

NACK again - I tell you why below.

Quoted 37 lines
---
 scripts/Makefile           |  1 -
 scripts/gdb/Makefile       |  1 -
 scripts/gdb/linux/Makefile | 11 -----------
 scripts/gdb/vmlinux-gdb.py |  2 +-
 4 files changed, 1 insertion(+), 14 deletions(-)
 delete mode 100644 scripts/gdb/Makefile
 delete mode 100644 scripts/gdb/linux/Makefile
scripts/Makefile +0 -1
index 2016a64..72902b5 100644
@@ -36,7 +36,6 @@ subdir-$(CONFIG_MODVERSIONS) += genksyms
 subdir-y                     += mod
 subdir-$(CONFIG_SECURITY_SELINUX) += selinux
 subdir-$(CONFIG_DTC)         += dtc
-subdir-$(CONFIG_GDB_SCRIPTS) += gdb
 
 # Let clean descend into subdirs
 subdir-	+= basic kconfig package
scripts/gdb/Makefile deleted +0 -1
deleted file mode 100644
index 62f5f65..0000000
@@ -1 +0,0 @@
-subdir-y := linux
scripts/gdb/linux/Makefile deleted +0 -1
deleted file mode 100644
index 6cf1ecf..0000000
@@ -1,11 +0,0 @@
-always := gdb-scripts

scripts/gdb/linux/Makefile line 11

Quoted 10 lines
scripts/gdb/linux/Makefile deleted +0 -10
-
-SRCTREE := $(shell cd $(srctree) && /bin/pwd)
-
-$(obj)/gdb-scripts:
-ifneq ($(KBUILD_SRC),)
-	$(Q)ln -fsn $(SRCTREE)/$(obj)/*.py $(objtree)/$(obj)
-endif
-	@:
-
-clean-files := *.pyc *.pyo $(if $(KBUILD_SRC),*.py)

This step I don't understand at all. Why do you want to destroy the possibility to automatically load the scripts? Did you read Documentation/gdb-kernel-debugging.txt in this regard?

scripts/gdb/vmlinux-gdb.py line 16

Quoted 10 lines
scripts/gdb/vmlinux-gdb.py +1 -1
index ce82bf5..a9029f4 100644
@@ -13,7 +13,7 @@
 
 import os
 
-sys.path.insert(0, os.path.dirname(__file__) + "/scripts/gdb")
+sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))

This works only so far as that (if you don't destroy the link) the main script will still find its modules. However, *.pyc files are then generated in the source tree, no longer in the output dirs. The code is designed to prevent this.

You still don't explain to us why the existing code doesn't work for you and how you prefer to use it instead.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RTC ITP SES-DE
Corporate Competence Center Embedded Linux
author
#2 lore raw
Quoted 80 lines · Jan Kiszka
Quoted 5 lines · yalin wang

we insert __file__'s real path into sys.path,
so that no matter we import the vmlinux-gdb.py from $OUT floder or from source code folder, we can always find the linux/ lib folder, and we don't need create link to linux/*.py files, remove the related make file.

NACK again - I tell you why below.

Quoted 37 lines

---

scripts/Makefile           |  1 -
scripts/gdb/Makefile       |  1 -
scripts/gdb/linux/Makefile | 11 -----------
scripts/gdb/vmlinux-gdb.py |  2 +-
4 files changed, 1 insertion(+), 14 deletions(-)

delete mode 100644 scripts/gdb/Makefile
delete mode 100644 scripts/gdb/linux/Makefile

scripts/Makefile +0 -0
index 2016a64..72902b5 100644
@@ -36,7 +36,6 @@ subdir-$(CONFIG_MODVERSIONS) += genksyms

subdir-y += mod
subdir-$(CONFIG_SECURITY_SELINUX) += selinux
subdir-$(CONFIG_DTC) += dtc
-subdir-$(CONFIG_GDB_SCRIPTS) += gdb

# Let clean descend into subdirs
subdir- += basic kconfig package

scripts/gdb/Makefile deleted +0 -1
deleted file mode 100644
index 62f5f65..0000000
@@ -1 +0,0 @@
-subdir-y := linux
scripts/gdb/linux/Makefile deleted +0 -1
deleted file mode 100644
index 6cf1ecf..0000000
@@ -1,11 +0,0 @@
-always := gdb-scripts

scripts/gdb/linux/Makefile line 11

Quoted 10 lines
scripts/gdb/linux/Makefile deleted +0 -10
-
-SRCTREE := $(shell cd $(srctree) && /bin/pwd)
-
-$(obj)/gdb-scripts:
-ifneq ($(KBUILD_SRC),)
-	$(Q)ln -fsn $(SRCTREE)/$(obj)/*.py $(objtree)/$(obj)
-endif
-	@:
-
-clean-files := *.pyc *.pyo $(if $(KBUILD_SRC),*.py)

This step I don't understand at all. Why do you want to destroy the possibility to automatically load the scripts? Did you read Documentation/gdb-kernel-debugging.txt in this regard?

scripts/gdb/vmlinux-gdb.py line 16

Quoted 10 lines
scripts/gdb/vmlinux-gdb.py +0 -0
index ce82bf5..a9029f4 100644
@@ -13,7 +13,7 @@
 

import os

scripts/gdb/vmlinux-gdb.py +1 -1
-sys.path.insert(0, os.path.dirname(__file__) + "/scripts/gdb")
+sys.path.insert(0, os.path.dirname(os.path.realpath(__file__)))

This works only so far as that (if you don't destroy the link) the main script will still find its modules. However, *.pyc files are then generated in the source tree, no longer in the output dirs. The code is designed to prevent this.

Quoted 5 lines

You still don't explain to us why the existing code doesn't work for you and how you prefer to use it instead.

Jan

Thanks for your explanation,
the reason i change it is because i was doing cross platform debug , debug arm platform on x86 host .
and i only have source code on host ,
i don’t build it ..
Then when i start up gdb-arm , i want load its gdb scripts from source code . that is the usage i need .

i don’t want build kernel on all host when i just want debug an embedded platform occasionally .

Thanks