bash
文章平均质量分 73
sitelist
这个作者很懒,什么都没留下…
展开
-
uniq源代码分析
原创 2021-03-17 17:14:41 · 177 阅读 · 0 评论 -
uniq常用选项-c-d-u的来源和3种显示方式或3种基本用法
-c, --count prefix lines by the number of occurrences\n\ -d, --repeated only print duplicate lines, one for each group\n\"), stdout); -u, --unique only print unique lines\n\原创 2021-03-17 15:14:05 · 360 阅读 · 0 评论 -
uniq -d选项源代码分析
[root@localhost src]# gdb ./uniqGNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-94.el7Copyright (C) 2013 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free t原创 2021-03-17 14:54:16 · 387 阅读 · 0 评论 -
uniq -c 源代码调试
[root@localhost src]# gdb ./uniqGNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-94.el7Copyright (C) 2013 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software: you are free t原创 2021-03-17 14:16:10 · 314 阅读 · 0 评论 -
bash源代码分析----静态编译bash的步骤和gdb如何调试子进程
静态编译bash的步骤:第一步:yum install glibc-static第二步:./configure --enable-static-link --without-bash-mallocmakemake install第三步:如果没有安装termcap库,下载安装termcap库wget http://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gztar -xzvf termcap-1.3.1.tar.gzcd termcap-1.原创 2021-03-16 15:47:22 · 588 阅读 · 0 评论 -
bash源代码分析----make_child函数断点bt3可以方便的看出子进程将要执行什么命令
(gdb) cContinuing.Breakpoint 4, make_child (command=command@entry=0x0, async_p=0) at jobs.c:17121712 {(gdb) bt 3#0 make_child (command=command@entry=0x0, async_p=0) at jobs.c:1712#1 0x0000000000449204 in command_substitute ( string=string@e...原创 2021-03-15 17:26:15 · 184 阅读 · 0 评论 -
bash源代码分析----子进程执行完make_child函数中的fork函数,然后执行shell_execve函数
子进程执行完make_child函数中的fork函数,然后执行shell_execve函数而父进程执行到wait_for函数等待子进程返回。关键的一部分内容啊。子进程需要在shell_execve函数处下断点。至此,我们有几个关键的断点。第一个,rl_newline函数,输入ls命令回车后会停到rl_newline函数处。第二个,父进程执行到wait_for函数处等待。第三个,子进程执行到shell_execve函数处开始执行ls命令。/* Call execve (), h原创 2021-03-15 10:58:02 · 329 阅读 · 0 评论 -
bash源代码分析----父进程的wait_for函数什么时候返回
(gdb) n758 stop_pipeline (asynchronous, (COMMAND *)NULL);(gdb) n760 if (asynchronous)(gdb) n775 exec_result = wait_for (last_made_pid);(gdb) n_父进程执行到这里开始等待子进程返回。而子进程被我们停在了pipe_read函数的 ...原创 2021-03-15 10:38:50 · 214 阅读 · 0 评论 -
bash源代码分析----子进程中__read_nocancel函数什么时候返回
下面是调试的父进程[root@localhost bash-4.2.53]# gdb ./bashGNU gdb (GDB) Red Hat Enterprise Linux 7.6.1-94.el7Copyright (C) 2013 Free Software Foundation, Inc.License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free softw原创 2021-03-15 10:23:06 · 626 阅读 · 1 评论 -
bash源代码分析之execute_disk_command函数分析
parent_return特别的有这么一个标识符。make_child函数返回后,根据pid是0还是进程号execute_disk_command函数又有不同的执行走向。(gdb) n1918 sigprocmask (SIG_SETMASK, &oset, (sigset_t *)NULL);(gdb) n1922 }(gdb) nexecute_disk_command (cmdflags=0, fds_to_close=0xaada08, a...原创 2021-03-15 09:25:54 · 247 阅读 · 0 评论 -
bash源代码分析之make_child函数分析
make_child函数,主要是一个if,else结构要看明白。if语句里面是在子进程里面运行。else语句是在父进程里面运行。子进程是父进程的一个拷贝,要执行ls命令,还要有exec函数出现啊。(gdb) nSingle stepping until exit from function fork,which has no line number information.Detaching after fork from child process 20558.make_child原创 2021-03-15 09:02:42 · 412 阅读 · 0 评论 -
bash源代码分析----bash里面的dollar_dollar_pid
(gdb) b getpidBreakpoint 1 at 0x41b070(gdb) cThe program is not being run.(gdb) rStarting program: /root/bash-4.2.53/./bashBreakpoint 1, 0x00007ffff76a5890 in getpid () from /lib64/libc.so.6Missing separate debuginfos, use: debuginfo-install glibc-原创 2021-03-15 08:32:02 · 207 阅读 · 3 评论 -
bash源代码分析----make_child函数分析调用fork函数才能执行ls这样的simple_command
(gdb) b forkBreakpoint 3 at 0x7ffff76a4924(gdb) cContinuing.Breakpoint 3, 0x00007ffff76a4924 in fork () from /lib64/libc.so.6(gdb) bt#0 0x00007ffff76a4924 in fork () from /lib64/libc.so.6#1 0x0000000000440e38 in make_child (command=0xaae268 "ls -..原创 2021-03-12 16:54:42 · 195 阅读 · 0 评论 -
bash源代码分析----阶段性总结用gdb分析的方法
一,用gdb分析,分析主要用到了break,print,next,step,info,finish,run,continue,quit等命令二,分析的内容1:(1),提示字符串是如何打印出来的(2),ls和回车符三个字符是如何输入的(3),ls命令这个simple_command是如何被执行的。三,分析的内容2:set命令是如何被实现的,比如set -n和bash -n是一个意思。四,分析的内容3:重定向是如何实现的,比如ls >1.txt。五,分析的内容4:.原创 2021-03-12 14:24:43 · 370 阅读 · 0 评论 -
bash源代码分析----execute_command函数执行ls的具体过程
(gdb) sexecute_command (command=0xa996c8) at execute_cmd.c:372372 {(gdb) bt#0 execute_command (command=0xa996c8) at execute_cmd.c:372#1 0x000000000041e253 in reader_loop () at eval.c:152#2 0x000000000041c88e in main (argc=1, argv=0x7fffffffe2a...原创 2021-03-12 14:00:43 · 1567 阅读 · 0 评论 -
bash源代码分析----rl_newline函数是在_rl_dispatch_subseq 函数里面调用的
(gdb) n760 switch (map[key].type)(gdb) p key$6 = 13(gdb) p map[key].type$7 = 0 '\000'(gdb) n763 func = map[key].function;(gdb) n764 if (func)(gdb) p func$8 = (rl_command_func_t *) 0x4a01c0 <rl_newline>(gdb)i...原创 2021-03-11 14:50:01 · 158 阅读 · 0 评论 -
bash源代码分析----_rl_dispatch函数处理输入的每一个字符,最后处理回车符13
/* Do the command associated with KEY in MAP. If the associated command is really a keymap, then read another key, and dispatch into that map. */int_rl_dispatch (key, map) register int key; Keymap map;{ _rl_dispatching_keymap = map;...原创 2021-03-11 14:39:15 · 215 阅读 · 0 评论 -
bash源代码分析----readline_internal_char函数读取输入的字符
STATIC_CALLBACK int#if defined (READLINE_CALLBACKS)readline_internal_char ()#elsereadline_internal_charloop ()#endif{ static int lastc, eof_found; int c, code, lk; lastc = -1; eof_found = 0;#if !defined (READLINE_CALLBACKS) while (rl_done...原创 2021-03-11 14:11:47 · 236 阅读 · 0 评论 -
bash源代码分析----readline_internal_charloop函数输入命令的功能是如何实现的
(gdb) n405 RL_CHECK_SIGNALS ();(gdb) n406 }(gdb) nreadline_internal () at readline.c:593593 eof = readline_internal_charloop ();原创 2021-03-11 11:49:35 · 142 阅读 · 0 评论 -
bash源代码分析----rl_redisplay函数分析
(gdb) p rl_display_prompt$36 = 0x726c88 "[root@localhost bash-4.2.53]# "此函数比较大,慢慢分析。rl_display_prompt确实是指向了提示字符串。现在的任务还是,什么时候,哪个函数里面具体打印出提示字符串的?/* Basic redisplay algorithm. */voidrl_redisplay (){ register int in, out, c, linenum, cursor_line.原创 2021-03-11 11:24:12 · 531 阅读 · 0 评论 -
bash源代码分析----readline_internal_setup函数会打印出提示字符串
(gdb) n394 (*rl_redisplay_function) ();(gdb) n[root@localhost bash-4.2.53]# 398 if (rl_editing_mode == vi_mode)(gdb)STATIC_CALLBACK voidreadline_internal_setup (){ char *nprompt; _rl_in_stream = rl_instream; _rl_out_strea...原创 2021-03-11 11:12:45 · 165 阅读 · 0 评论 -
bash源代码分析----readline_internal_setup函数分析
readline_internal_setup函数里面打印出提示字符串,离目标又近了一步。/* Read a line of input from the global rl_instream, doing output on the global rl_outstream. If rl_prompt is non-null, then that is our prompt. */static char *readline_internal (){ int eof;...原创 2021-03-11 10:59:51 · 199 阅读 · 0 评论 -
bash源代码分析----yy_readline_get函数主要是调用了readline函数
/* **************************************************************** *//* *//* Let input be read from readline (). *//* *//* **************************************...原创 2021-03-11 10:15:45 · 122 阅读 · 0 评论 -
bash源代码分析----yy_getc函数分析
(gdb) syy_readline_get () at ./parse.y:14271427 {(gdb) p *(bash_input.getter)$29 = {int (void)} 0x41e830 <yy_readline_get>(gdb)shell_getc函数会调用yy_getc函数yy_getc函数就是一个指针引用/* Call this to get the next character of input. */static intyy_ge...原创 2021-03-11 10:11:11 · 375 阅读 · 0 评论 -
bash源代码分析----read_token函数调用shell_getc函数返回10也就是回车符
/* Function for yyparse to call. yylex keeps track of the last two tokens read, and calls read_token. */static intyylex (){ if (interactive && (current_token == 0 || current_token == '\n')) { /* Before we print a prompt, we might...原创 2021-03-11 09:35:59 · 225 阅读 · 0 评论 -
bash源代码分析----read_token函数调用了shell_getc函数
/* Read the next token. Command can be READ (normal operation) or RESET (to normalize state). */static intread_token (command) int command;{ int character; /* Current character. */ int peek_char; /* Temporary look-ahead charact...原创 2021-03-10 17:16:50 · 223 阅读 · 0 评论 -
bash源代码分析----yylex函数分析和decode_prompt_string函数负责分析并返回提示字符串
yylex函数调用位置:y.tab.c中if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; }/* Function for yyparse to call. yylex keeps track of the last two tokens read, and calls read_token. */static intyylex (...原创 2021-03-10 16:55:58 · 663 阅读 · 0 评论 -
bash源代码分析----bison--debug或-t选项的作用
bison--debug或-t选项的作用bison -y parse.y/* Debug traces. */#ifndef YYDEBUG# define YYDEBUG 0#endif#if YYDEBUGextern int yydebug;#endifbison -y --debug parse.y/* Debug traces. */#ifndef YYDEBUG# define YYDEBUG 1#endif#if YYDEBUGextern int yydeb..原创 2021-03-10 11:03:43 · 459 阅读 · 0 评论 -
bash源代码分析----打印提示符是如何实现的和get_string_value函数获取环境变量的值
/* Return the string value of a variable. Return NULL if the variable doesn't exist, or only has a function as a value. Don't cons a new string. */char *get_string_value (var_name) char *var_name;{ SHELL_VAR *var = find_variable (var_name...原创 2021-03-09 16:25:28 · 162 阅读 · 0 评论 -
bash源代码分析----bash --login的作用和--noprofile的作用
[root@localhost ~]# cat ~/.bash_profile# .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then . ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/binexport PATHlshell="login shell will see this ...原创 2021-03-09 15:22:51 · 1787 阅读 · 0 评论 -
bash源代码分析----maybe_execute_file函数分析
执行哪些启动脚本? if (act_like_sh) maybe_execute_file ("~/.profile"); else { if (maybe_execute_file ("~/.bash_profile") == 0) if (maybe_execute_file ("~/.bash_login") == 0) maybe_execute_file ("~/.profile");...原创 2021-03-09 15:08:10 · 163 阅读 · 0 评论 -
bash源代码分析之shell.c中mail函数对HISTFILE的处理
/* Initialize the interactive history stuff. */ if (!shell_initialized) { char *hf = get_string_value ("HISTFILE"); if (hf) read_history (hf); } } /* Save the history of executed commands. */ if (inter...原创 2021-03-09 11:50:14 · 178 阅读 · 0 评论 -
bash源代码分析----shell_initialize函数和variables.c的关系
/* Do whatever is necessary to initialize the shell. Put new initializations in here. */shell_initialize (){ /* Line buffer output for stderr. If your machine doesn't have either of setlinebuf or setvbuf, you can just comment out the buffer...原创 2021-03-09 11:43:14 · 314 阅读 · 1 评论 -
bash源代码分析----after_flags之前处理flags和after_flags之后初始化shell_initialize函数和read_and_execute部分
第一部分:after_flags之前处理flags第二部分:after_flags之后初始化shell_initialize函数第三部分:read_and_execute部分main (argc, argv, env) int argc; char **argv, **env;{ int i, arg_index = 1; extern int yydebug; FILE *default_input = stdin; char *local_pend...原创 2021-03-09 11:36:36 · 195 阅读 · 0 评论 -
bash源代码分析----login shell登录shell和interactive交互式shell的关系以及main函数中的change_flag_char函数
/* Non-zero means that this shell is a login shell. Specifically: 0 = not login shell. 1 = login shell from getty (or equivalent fake out) -1 = login shell from "-login" flag. -2 = both from getty, and from flag.*/int login_shell = -2;/* ...原创 2021-03-09 11:06:25 · 209 阅读 · 0 评论 -
bash源代码分析----shell_builtins[]数组和shell_flags[]数组的一一对应关系
builtins.c文件中的 shell_builtins[]数组和struct builtin shell_builtins[] = { { "set", set_builtin, 1, "set [-aefhkntuvx] [arg ...]]", " -a Mark variables which are modified or created for export\n\ -e Exit immediately if a command exits wit...原创 2021-03-09 10:36:29 · 267 阅读 · 0 评论 -
bash源代码分析----set_builtin函数和change_flag函数的关系
下面的文件的来源:http://www.oldlinux.org/Linux.old/gnu/bash/bash-1.05-linux.tar.gzset命令和flags.c文件密切相关。/* builtins.h -- a list of all commands that are shell builtins. See builtins.c to see where to add more builtins. */#include "config.h"int colon...原创 2021-03-09 10:24:14 · 361 阅读 · 0 评论 -
bash源代码分析之重定向----do_redirection_internal()函数
/* Do the specific redirection requested. Returns errno in case of error. If FOR_REAL is zero, then just do whatever is neccessary to produce the appropriate side effects. REMEMBERING, if non-zero, says to remember how to undo each redirection....原创 2021-03-03 15:35:13 · 127 阅读 · 1 评论