Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Moh Kh
bs
Commits
e68bd7b1
Commit
e68bd7b1
authored
3 years ago
by
Peter Gerwinski
Browse files
Options
Downloads
Patches
Plain Diff
Notizen 25.4.2022
parent
4a3900e5
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
20220425/bs-20220425.txt
+64
-0
64 additions, 0 deletions
20220425/bs-20220425.txt
with
64 additions
and
0 deletions
20220425/bs-20220425.txt
0 → 100644
+
64
−
0
View file @
e68bd7b1
Von der Anwendung bis zum Kernel: libc, 14.05.2021, 14:17:04
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$ gcc -Wall -O -g3 hello-1.c -o hello-1
$ gdb -tui ./hello-1
(gdb) b 5 # setze Breakpoint vor printf()-Aufruf
(gdb) run
(gdb) step # springe in die aufgerufene Funktion hinein
(gdb) directory libc/glibc-2.28/libio # Verzeichnis für Quelltext mitteilen
--> _IO_puts()
(gdb) next # 1 Zeile ausführen
--> _IO_sputn() # springe in die aufgerufene Funktion hinein
--> IO_validate_vtable() # In dieser Funktion landen wir stattdessen.
--> return vtable;
--> "Hello, world!\n" erscheint auf dem Bildschirm.
--> ???
_IO_sputn() ist keine Funktion, sondern ein Präprozessor-Makro,
der _IO_XSPUTN() aufruft.
_IO_XSPUTN() ist keine Funktion, sondern ein Präprozessor-Makro,
der JUMP2() aufruft und zusätzlich __xsputn
als ersten Parameter übergibt.
JUMP2() ist keine Funktion, sondern ein Präprozessor-Makro,
der die Funktion _IO_JUMPS_FUNC(THIS)->FUNC() aufruft
und zusätzlich THIS als ersten Parameter übergibt.
FUNC hat hierbei den Wert __xsputn, und
THIS hat den Wert FP, also die Datei, hier also stdout.
_IO_JUMPS_FUNC() ist keine Funktion, sondern ein Präprozessor-Makro,
der ...
# define _IO_JUMPS_FUNC(THIS) \
(IO_validate_vtable \
(*(struct _IO_jump_t **) ((void *) &_IO_JUMPS_FILE_plus (THIS) \
+ (THIS)->_vtable_offset)))
... prüft, ob die virtuelle Methodentabelle (vtable) in Ordnung ist
und einen Zeiger darauf zurückliefert.
Anschließend kann JUMP2() die tatsächliche Funktion __xsputn() aufrufen.
Gesamtergebnis:
_IO_sputn() ist eine virtuelle Methode der Datei.
THIS hat den Wert der Datei, hier also stdout.
...
--> return vtable;
--> _IO_new_file_xsputn()
_IO_default_xsputn (f, ...)
--> _IO_OVERFLOW (f, EOF)
--> IO_valudate_vtable() # Aufruf einer virtuellen Methode
--> _IO_new_file_overflow()
--> _IO_do_write (f, ...) # Präprozessor-Makro für ...
--> _IO_new_do_write (f, ...)
... Schleife ...
Datei fileops.c, Zeile 791
--> _IO_new_do_write (f, ...)
--> new_do_write (f, ...)
--> _IO_SYSWRITE (fp, ...)
--> __libc_write()
Datei sysdeeps/unix/sysv/linux/write.c, Zeile 26
--> return SYSCALL_CANCEL (write, fd, buf, nbytes);
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment