Skip to contentSkip to conversation

scripts/gdb: fix get_thread_info

PATCH Applied Xi Kangjie 3 participants 4 messages Jan 18, 2018 GDB kernel debugging helper scripts

lore
Share & tools
lore

Xi Kangjie

author
#0 lore raw

PATCH 1/1 scripts/gdb: fix get_thread_info

Since kernel 4.9, the thread_info has been moved into task_struct, no longer locates at the bottom of kernel stack.

See commits:
- commit c65eacbe290b ("sched/core: Allow putting thread_info into task_struct")
- commit 15f4eae70d36 ("x86: Move thread_info into task_struct")

Before fix:
(gdb) set $current = $lx_current()
(gdb) p $lx_thread_info($current)
$1 = {flags = 1470918301}
(gdb) p $current.thread_info
$2 = {flags = 2147483648}

After fix:
(gdb) p $lx_thread_info($current)
$1 = {flags = 2147483648}
(gdb) p $current.thread_info
$2 = {flags = 2147483648}

---
 scripts/gdb/linux/tasks.py | 2 ++
 1 file changed, 2 insertions(+)
scripts/gdb/linux/tasks.py +2 -0
index 1bf949c43b76..f6ab3ccf698f 100644
@@ -96,6 +96,8 @@ def get_thread_info(task):
         thread_info_addr = task.address + ia64_task_size
         thread_info = thread_info_addr.cast(thread_info_ptr_type)
     else:
+        if task.type.fields()[0].type == thread_info_type.get_type():
+            return task['thread_info']
         thread_info = task['stack'].cast(thread_info_ptr_type)
     return thread_info.dereference()
 
Signature · 1 line
2.13.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 32 lines · Xi Kangjie

Since kernel 4.9, the thread_info has been moved into task_struct, no longer locates at the bottom of kernel stack.

See commits:
- commit c65eacbe290b ("sched/core: Allow putting thread_info into task_struct")
- commit 15f4eae70d36 ("x86: Move thread_info into task_struct")

Before fix:
(gdb) set $current = $lx_current()
(gdb) p $lx_thread_info($current)
$1 = {flags = 1470918301}
(gdb) p $current.thread_info
$2 = {flags = 2147483648}

After fix:
(gdb) p $lx_thread_info($current)
$1 = {flags = 2147483648}
(gdb) p $current.thread_info
$2 = {flags = 2147483648}

---
 scripts/gdb/linux/tasks.py | 2 ++
 1 file changed, 2 insertions(+)
scripts/gdb/linux/tasks.py +0 -0
index 1bf949c43b76..f6ab3ccf698f 100644

scripts/gdb/linux/tasks.py def get_thread_info(task): · line 103

Quoted 8 lines
scripts/gdb/linux/tasks.py +2 -0
@@ -96,6 +96,8 @@ def get_thread_info(task):
         thread_info_addr = task.address + ia64_task_size
         thread_info = thread_info_addr.cast(thread_info_ptr_type)
     else:
+        if task.type.fields()[0].type == thread_info_type.get_type():
+            return task['thread_info']
         thread_info = task['stack'].cast(thread_info_ptr_type)
     return thread_info.dereference()
 

Andrew, please pick up.

Thanks,
Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux
maintainer Acked-by
#2 lore raw
Quoted 44 lines · Jan Kiszka
Quoted 32 lines · Xi Kangjie

Since kernel 4.9, the thread_info has been moved into task_struct, no longer locates at the bottom of kernel stack.

See commits:
- commit c65eacbe290b ("sched/core: Allow putting thread_info into task_struct")
- commit 15f4eae70d36 ("x86: Move thread_info into task_struct")

Before fix:
(gdb) set $current = $lx_current()
(gdb) p $lx_thread_info($current)
$1 = {flags = 1470918301}
(gdb) p $current.thread_info
$2 = {flags = 2147483648}

After fix:
(gdb) p $lx_thread_info($current)
$1 = {flags = 2147483648}
(gdb) p $current.thread_info
$2 = {flags = 2147483648}

---
 scripts/gdb/linux/tasks.py | 2 ++
 1 file changed, 2 insertions(+)
scripts/gdb/linux/tasks.py +0 -0
index 1bf949c43b76..f6ab3ccf698f 100644

scripts/gdb/linux/tasks.py def get_thread_info(task): · line 103

Quoted 8 lines
scripts/gdb/linux/tasks.py +2 -0
@@ -96,6 +96,8 @@ def get_thread_info(task):
         thread_info_addr = task.address + ia64_task_size
         thread_info = thread_info_addr.cast(thread_info_ptr_type)
     else:
+        if task.type.fields()[0].type == thread_info_type.get_type():
+            return task['thread_info']
         thread_info = task['stack'].cast(thread_info_ptr_type)
     return thread_info.dereference()
 
Quoted 1 line

Andrew, please pick up.

However, should we mark this as:
Cc: <[email protected]> # 4.9+ ?

Regards

--
Kieran

maintainer
#3 lore raw
Quoted 46 lines · Kieran Bingham
Quoted 44 lines · Jan Kiszka
Quoted 32 lines · Xi Kangjie

Since kernel 4.9, the thread_info has been moved into task_struct, no longer locates at the bottom of kernel stack.

See commits:
- commit c65eacbe290b ("sched/core: Allow putting thread_info into task_struct")
- commit 15f4eae70d36 ("x86: Move thread_info into task_struct")

Before fix:
(gdb) set $current = $lx_current()
(gdb) p $lx_thread_info($current)
$1 = {flags = 1470918301}
(gdb) p $current.thread_info
$2 = {flags = 2147483648}

After fix:
(gdb) p $lx_thread_info($current)
$1 = {flags = 2147483648}
(gdb) p $current.thread_info
$2 = {flags = 2147483648}

---
 scripts/gdb/linux/tasks.py | 2 ++
 1 file changed, 2 insertions(+)
scripts/gdb/linux/tasks.py +0 -0
index 1bf949c43b76..f6ab3ccf698f 100644

scripts/gdb/linux/tasks.py def get_thread_info(task): · line 103

Quoted 8 lines
scripts/gdb/linux/tasks.py +2 -0
@@ -96,6 +96,8 @@ def get_thread_info(task):
         thread_info_addr = task.address + ia64_task_size
         thread_info = thread_info_addr.cast(thread_info_ptr_type)
     else:
+        if task.type.fields()[0].type == thread_info_type.get_type():
+            return task['thread_info']
         thread_info = task['stack'].cast(thread_info_ptr_type)
     return thread_info.dereference()
 
Quoted 7 lines
Quoted 1 line

Andrew, please pick up.

However, should we mark this as:
Cc: <[email protected]> # 4.9+ ?

Yes, good point.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT RDA IOT SES-DE
Corporate Competence Center Embedded Linux