1. Loaded Programs
1.1 Commandnm
Commandnmcan be used to display symbol information in both objects and binary files, because it looks at the symbol table stored in the binary for debugging purposes. Commandstripcan be used to remove the symbol table.
Option–nasksnmto sort the output by symbol address. The addresses are virtual memory addresses, because the system uses the virtual memory hardware to keep each process in its own virtual address space.
In the output of nm,etextis a symbol defined by the linker to let you know where the end of test is, andedatareports the address where the initialized data terminates.
1.2 What does the system (kernel) loader do?
·The header in the binary file reports the memory size required for the program text, and the file keeps the memory image of that text. Therefore, the system can just copy all this into memory. For a given system and architecture, there is a convention regarding which addresses the program must use. Therefore, the system knows where to load the program.
·The header in the binary reports the memory size required for initialized variables (global) and file contains a memory image for them. Thus, the system can copy those bytes to memory. Note that the system has no idea regarding where does one variable start or how big it is. The system only knows how many bytes it has to copy to memory, and at which address should they be copied.
·For uninitialized global variables, the binary header reports their total size. The system allocates that amount of memory for the program. That is all it has to do. As a courtesy, Plan 9 guarantees that such memory is initialized with all bytes being zero. This means that all your global variables are initialized to null values by default.
1.3 Memory image for the global program
The virtual memory of a process in Plan 9 has several segments. A memory segment is a portion of contiguous memory with some properties. Segments used by a Plan 9 process are:
·Thetest segment. It contains instructions that can be executed but not modified. The hardware is used by the system to enforce these permissions. The memory is initialized by the system with the program text (code) kept within the binary file for the program.
·Thedata segment. It contains the initialized data for the program. Protection is set to allow both read and write operations on it, but you cannot execute instructions on it. The memory is initialized by the system using the initialized data kept within the binary file for the program.
·The uninitialized data segment, calledbss segment, which is almost like the data segment. However, this one is initialized by zeroing its memory. The name of the segment comes from an arcane instruction used to implement it on a machine that no longer exists. How much memory is given depends on the size recorded in the binary file. Moreover, this segment cangrow, by using a system call that allocates more memory for it. Function libraries likemalloccause this segment to grow when they consume all the available memory in this segment. This is the reason for the gap between this segment and the stack segment, to leave room for the segment to grow.
·Thestack segmentis also used for reading and writing memory. Unlike other segments, this segment seems to grow automatically when more space is used. It is used to keep the stack for the process.
1.4 Process Arguments
The macrosARGBEGINandARGENDloop through the argument list, removing and processing
options. After ARGEND, both argc and argv reflect the argument list without any option.
Between both macros, we must write the body for a switch statement (supplied by
ARGBEGIN), with a case per option.
Macros defined in plan9.h
Most of the Plan 9 programs that accept multiple options use these macros to process their
argument list in search for options. This means that the invocation syntax is similar for most pro-grams. You may combine options in a single argument, use multiple arguments, supply arguments for options immediately after the option letter, or use another argument,
terminate the option list by giving a -- argument, and so on.
Source code of bind.c
1.5 System call errors
There are several ways of printing out the error string. The most convenient way is using the format “%r” in print.
There is a function that both prints a message and exits. It is calledsysfatal, and is used like follows.
The system callrerrstrreads the error string. It stores the string at the buffer you supply.
The system callwerrstrwrites a new value for the error string. It is used like theprint. Using it, we can implement a function thatpopsan element from a stack and reports errors nicely:
1.6 Environment
To obtain the value for a environment variable, from a C program, we can use thegetenvsystem call. If the variable is not defined,getenvreturns a null string. A related call isputenv, which accepts a name and a value, and set the corresponding environment variable accordingly.
1.7 Process States
1.8 Debugging
The programsrcknows how to obtain the source file name and line number that corresponds to that program counter.
; src -n -s 0x000016ff 8.hi
/sys/src/libc/fmt/dofmt.c:37
Option -n causes the source file name and line to be printed. Otherwise src would ask your editor to display your file and line. Option -s permits you to give a memory address or a symbol name to locate its source.
acidis the debugger can be used to dump the stack (function stk()), memory (function mem()) and so on.
分享到:
相关推荐
涵盖了编程和数据结构的基础知识,并为初学计算机科学的学生提供了不仅编写程序的机会,而且还提供了证明定理和分析算法的机会。
Gottschling introduces key concepts using examples from many technical problem domains, drawing on his extensive experience training professionals and teaching C++ to students of physics, math, and ...
This book presents the foundations of theoretical computer science in a format ... and complexity theory with an introduction to some of the open classification problems relating to the classes P and NP.
Chapter 14: Introduction to inheritance 459 14.1 POLYGONS AND RECTANGLES 460 14.2 POLYMORPHISM 467 14.3 TYPING FOR INHERITANCE 472 14.4 DYNAMIC BINDING 480 14.5 DEFERRED FEATURES AND CLASSES 482 14.6 ...
### Concrete Abstraction: An Introduction to Computer Science Using Scheme #### 标题解读 - **Concrete Abstraction**: 这一术语在计算机科学中具有特殊含义。它指的是通过具体的例子来理解抽象概念的方法,...
Gottschling introduces key concepts using examples from many technical problem domains, drawing on his extensive experience training professionals and teaching C++ to students of physics, math, and ...
Gottschling introduces key concepts using examples from many technical problem domains, drawing on his extensive experience training professionals and teaching C++ to students of physics, math, and ...
Work on a wide array of applications, from simple batch jobs to stream processing and machine learning Explore the most common as well as some complex use-cases to perform large-scale data analysis ...
The book starts with a short introduction to the principles and the ecosystem of Redux, then moves on to show how to implement the basic elements of Redux and put them together. Afterward, you are ...
《Programming Abstractions in C》是一本深受欢迎的计算机科学教材,专注于通过C语言教授编程抽象的概念。这本书由Steven S. Skiena撰写,旨在帮助学生掌握编程基础,理解数据结构和算法,以及如何有效地使用C语言...
Authors Tom Hope, Yehezkel Resheff, and Itay Lieder provide a hands-on approach to TensorFlow fundamentals for a broad technical audience—from data scientists and engineers to students and ...
- **Introduction to Python**: Basics of the Python programming language. - **Data Structures**: Lists, dictionaries, and other data structures. - **Web Data Retrieval**: Techniques for retrieving data...
《深入理解System.Web.Abstractions.dll:一个关键的.NET框架组件》 在.NET开发中,经常会遇到“System.Web.Abstractions.dll”这个程序集,它是.NET Framework中一个不可或缺的部分,尤其在Web应用程序的开发中...
This book shows you how to evaluate the performance implications of various Clojure abstractions, discover their underpinnings, and apply the right approach for optimum performance in real-world ...
### Concrete Abstractions: An Introduction to Computer Science Using Scheme 《Concrete Abstractions》是一本关于计算机科学基础的教材,它采用了一种独特的教学方法,通过实际的例子和抽象的概念相结合的方式...
This book began about 20 years ago in the form of supplementary notes for my algebra classes. I wanted to discuss some concrete topics such as symmetry, linear groups, and quadratic number fields in...