C语言中出现[Error] assignment to expression with array type

1.原因

数组不能直接给数组赋值
指针不能直接给数组赋值

2.解决办法

char a[] = {'h','e','l','l','o'};
char b[5];
char* p = NULL;

//错误情况
char c[5] = a; // 不可直接将数组赋值给数组
char d[5] = p; // 不可将指针直接赋值给数组

//正确情况
*p = a; //将数组首元素地址赋值给指针 
strcpy(b,a);//使用标准字符拷贝函数对数组进行赋值
char **p1 = &p;//二级指针可以接收一级指针地址

结构体出现这种问题

需要使用strcpy或者strncpy函数拷贝

在这里插入图片描述

  • 27
    点赞
  • 58
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
一本不错的C#书,希望对您有帮助,本书目录: C# 3.0 Unleashed 1 Table of Contents 6 Introduction 30 Why This Book Is for You 31 Organization and Goals 32 Part 1 Learning C# Basics 36 1 Introducing the .NET Platform 38 What Is .NET? 38 The Common Language Runtime (CLR) 40 The .NET Framework Class Library (FCL) 43 C# and Other .NET Languages 45 The Common Type System (CTS) 46 The Common Language Specification (CLS) 46 Summary 46 2 Getting Started with C# and Visual Studio 2008 48 Writing a Simple C# Program 48 Creating a Visual Studio 2008 (VS2008) Project 52 Commenting Code 61 Identifiers and Keywords 64 Convention and Style 66 Variables and Types 67 Definite Assignment 73 Interacting with Programs 74 Summary 77 3 Writing C# Expressions and Statements 78 C# Operators 78 Statements 91 Blocks and Scope 92 Labels 92 Operator Precedence and Associativity 93 Selection and Looping Statements 94 Summary 106 4 Understanding Reference Types and Value Types 108 A Quick Introduction to Reference Types and Value Types 108 The Unified Type System 109 Reference Type and Value Type Memory Allocation 114 Reference Type and Value Type Assignment 117 More Differences Between Reference Types and Value Types 121 C# and .NET Framework Types 123 Nullable Types 131 Summary 132 5 Manipulating Strings 134 The C# String Type 134 The StringBuilder Class 151 Regular Expressions 153 Summary 158 6 Arrays and Enums 160 Arrays 160 The System.Array Class 166 Using Enum Types 168 The System.Enum struct 171 Summary 174 7 Debugging Applications with Visual Studio 2008 176 Stepping Through Code 176 Summary 188 Part 2 Object-Oriented Programming with C# 190 8 Designing Objects 192 Object Members 192 Instance and Static Members 193 Fields 194 Methods 195 Properties 196 Indexers 198 Reviewing Where Partial Types Fit In 199 Static Classes 200 The System.Object Class 201 Summary 204 9 Designing Object-Oriented Programs 206 Inheritance 207 Encapsulating Object Internals 213 Polymorphism 219 Summary 229 10 Coding Methods and Custom Operators 230 Methods 231 Overloading Methods 239 Overloading Operators 242 Conversions and Conversion Operator Overloads 247 Partial Methods 256 Extension Methods 257 Summary 259 11 Error and Exception Handling 260 Why Exception Handling? 261 Exception Handler Syntax: The Basic try/catch Block 261 Ensuring Resource Cleanup with finally Blocks 263 Handling Exceptions 264 Designing Your Own Exceptions 272 checked and unchecked Statements 274 Summary 277 12 Event-Based Programming with Delegates and Events 278 Exposing Delegates 279 Implementing Delegate Inference 285 Assigning Anonymous Methods 285 Coding Events 287 Summary 300 13 Naming and Organizing Types with Namespaces 302 Why Namespaces? 303 Namespace Directives 304 Creating Namespaces 307 Namespace Members 310 Scope and Visibility 311 Namespace Alias Qualifiers 312 Extern Namespaces Alias 313 Summary 315 14 Implementing Abstract Classes and Interfaces 316 Abstract Classes 317 Abstract Class and Interface Differences 319 Implementing Interfaces 320 Defining Interface Types 320 Implicit Implementation 322 Explicit Implementation 333 Interface Mapping 339 Interface Inheritance 341 Summary 344 Part 3 Applying Advanced C# Language Features 346 15 Managing Object Lifetime 348 Object Initialization 349 Object Initializers 355 Object Finalization 356 Automatic Memory Management 357 Proper Resource Cleanup 360 Interacting with the Garbage Collector 364 Summary 366 16 Declaring Attributes and Examining Code with Reflection 368 Using Attributes 369 Using Attribute Parameters 371 Attribute Targets 373 Creating Your Own Attributes 374 Using Reflection 378 Reflecting on Attributes 385 Summary 392 17 Parameterizing Type with Generics and Writing Iterators 394 Nongeneric Collections 395 Understanding the Benefits of Generics 395 Building Generic Types 401 Implementing Iterators 417 Summary 425 18 Using Lambda Expressions and Expression Trees 426 Lambda Expressions 427 Expression Trees 433 Summary 435 Part 4 Learning LINQ and .NET Data Access 436 19 Accessing Data with LINQ 438 LINQ to Objects 439 Querying Relational Data with LINQ to SQL 443 Standard Query Operators 456 Summary 468 20 Managing Data with ADO.NET 470 ADO.NET Architecture 470 Making Connections 474 Viewing Data 476 Manipulating Data 479 Calling Stored Procedures 481 Working with Disconnected Data 482 LINQ to DataSet 487 Summary 488 21 Manipulating XML Data 490 Streaming XML Data 491 Writing XML 491 Reading XML 494 Working with the XML DOM 495 Easier Manipulation with LINQ to XML 497 Summary 502 22 Creating Data Abstractions with the ADO.NET Entity Framework 504 An Overview of Entities 505 Starting the Entity Data Model in VS2008 505 Querying Entities with Entity SQL 509 Creating Custom Entities 511 Coding with LINQ to Entities 515 Summary 518 23 Working with Data in the Cloud with ADO.NET Data Services 520 Adding ADO.NET Data Services to Your Project 521 Accessing ADO.NET Data Services via HTTP URIs 522 Writing Code with the ADO.NET Data Services Client Library 528 Summary 533 Part 5 Building Desktop User Interfaces 534 24 Taking Console Applications to the Limit 536 Introducing the PasswordGenerator Console Application 537 Interacting with the User 537 Handling Command-Line Input 539 Adding Color and Positioning to Consoles 540 Summary 543 25 Writing Windows Forms Applications 544 Windows Forms Fundamentals 545 VS2008 Support for Windows Forms 548 Using Windows Forms Controls 557 MenuStrip, StatusStrip, and ToolStrip Controls 560 Data Grids and Data Binding 562 GDI+ Essentials 565 Additional Windows and Dialogs 568 Summary 574 26 Creating Windows Presentation Foundation (WPF) Applications 576 Just Enough XAML 577 Managing Layout 580 WPF Controls 589 Event Handling 602 Data Binding 603 Using Styles 607 Summary 609 Part 6 Designing Web User Interfaces 610 27 Building Web Applications with ASP.NET 612 The Web Application Model 612 Starting an ASP.NET Project with VS2008 615 A Lap Around an ASP.NET Page 617 Controls 622 State Management 625 Navigation 632 Theming a Site 638 Securing a Website 641 Data Binding 643 Summary 646 28 Adding Interactivity to Your Web Apps with ASP.NET AJAX 648 What Is AJAX? 648 Setting Up an ASP.NET AJAX Site 649 The AJAX Page Life Cycle 650 Loading Custom Script Libraries 652 ASP.NET AJAX Controls 654 Accessing Controls via JavaScript 657 Calling Web Services with ASP.NET AJAX 664 Summary 669 29 Crafting Rich Web Applications with Silverlight 670 What Makes Silverlight Tick? 670 Starting a Silverlight Project in VS2008 671 Handling Silverlight Events with C# 677 Playing Media 681 Animating UI Elements 684 Summary 686 Part 7 Communicating with .NET Technologies 688 30 Using .NET Network Communications Technologies 690 Implementing Sockets 690 Working with HTTP 698 Performing FTP File Transfers 700 Sending SMTP Mail 704 Summary 705 31 Building Windows Service Applications 708 Creating Windows Service Projects in VS2008 709 Coding Windows Services 712 Installing a Windows Service 717 Building a Controller to Communicate with a Windows Service 720 Summary 722 32 Remoting 724 Basic Remoting 724 Channels 735 Lifetime Management 738 Summary 741 33 Writing Traditional ASMX Web Services 742 Web Service Basics 742 Using Web Services 748 Summary 752 34 Creating Web and Services with WCF 754 Creating a WCF Application in VS2008 755 Creating a Web Service Contract 756 Implementing Web Service Logic 761 Configuring a Web Service 763 Consuming a Web Service 766 Summary 768 Part 8 Examining .NET Application Architecture and Design 770 35 Using the Visual Studio 2008 Class Designer 772 Visualizing Code 772 Building an Object Model with the Class Designer 778 Summary 783 36 Sampling Design Patterns in C# 784 Overview of Design Patterns 784 The Iterator Pattern 785 Implementing the Proxy Pattern 797 Implementing the Template Pattern 801 Summary 807 37 Building N-Tier/Layer Systems 808 Potential Drag-and-Drop Problems 808 Introducing N-Layer/N-Tier 810 N-Layer Architecture Examples 813 Summary 824 38 Automating Logic with Windows Workflow 826 Starting a Workflow Project 826 Building a Sequential Workflow 827 Building a State Workflow 832 Summary 842 Part 9 Surveying More of the .NET Framework Class Library 844 39 Managing Processes and Threads 846 .NET Process Support 847 Multithreading Overview 852 Thread Synchronization 855 Summary 858 40 Localizing and Globalization 860 Resource Files 860 Multiple Locales 872 Summary 880 41 Performing Interop (P/Invoke and COM) and Writing Unsafe Code 882 Unsafe Code 883 Platform Invoke 893 Communicating with COM from .NET 895 Exposing a .NET Component as a COM Component 898 Introduction to .NET Support for COM+ Services 900 Summary 905 42 Instrumenting Applications with System.Diagnostics Types 908 Simple Debugging 909 Conditional Debugging 910 Runtime Tracing 913 Making Assertions 915 Accessing Built-In Performance Counters 917 Implementing Timers 925 Building a Customized Performance Counter 926 Analyzing Performance with Sampling 937 Summary 946 Part 10 Deploying Code 948 43 Assemblies and Versioning 950 Inside Assemblies 950 Assembly Features 954 Configuration 956 Deployment 959 Summary 959 44 Securing Code 962 Code-Based Security 962 Role-Based Security 971 Security Utilities 973 Summary 974 45 Creating Visual Studio 2008 Setup Projects 976 Running the VS2008 Setup Project Wizard 976 Additional Setup Configuration 979 Summary 983 46 Deploying Desktop Applications 984 Deploying via ClickOnce 984 Configuring ClickOnce 986 Summary 988 47 Publishing Web Applications 990 The Anatomy of a Web Application 990 Web Server Setup 991 Virtual Directory Setup 992 Web Server Deployment 994 Publishing a Web App from VS2008 994 Summary 995 Part 11 Appendixes 996 A: Compiling Programs 998 Advanced 998 Assemblies 1000 B: Getting Help with the .NET Framework 1002 Read This Book 1002 Index 1003 .NET Framework Class Library Documentation 1003 Search Engines 1004 Favorite Websites 1004 Summary 1004
Get started in the world of software development: go from zero knowledge of programming to comfortably writing small to medium-sized programs in Python. Programming can be intimidating (especially when most books on software require you to know and use obscure command line instructions) but it doesn’t have to be that way! In Learn to Program with Python, author Irv Kalb uses his in-person teaching experience to guide you through learning the Python computer programming language. He uses a conversational style to make you feel as though he is your personal tutor. All material is laid out in a thoughtful manner, each lesson building on previous ones. Many real–world analogies make the material easy to relate to. A wide variety of well-documented examples are provided. Along the way, you’ll develop small programs on your own through a series of coding challenges that reinforce the content of the chapters What You Will Learn: Learn fundamental programming concepts including: variables and assignment statements, functions, conditionals, loops, lists, strings, file input and output, Internet data, and data structures Get comfortable with the free IDLE Interactive Development Environment (IDE), which you will use to write and debug all your Python code – no need to use the command line! Build text-based programs, including a number of simple games Learn how to re-use code by building your own modules Use Python’s built-in data structures and packages to represent and make use of complex data from the Internet
Ambiguous operators need parentheses -----------不明确的运算需要用括号括起 Ambiguous symbol ''xxx'' ----------------不明确的符号 Argument list syntax error ----------------参数表语法错误 Array bounds missing ------------------丢失数组界限符 Array size toolarge -----------------数组尺寸太大 Bad character in paramenters ------------------参数有不适当的字符 Bad file name format in include directive --------------------包含命令文件名格式不正确 Bad ifdef directive synatax ------------------------------编译预处理ifdef有语法错 Bad undef directive syntax ---------------------------编译预处理undef有语法错 Bit field too large ----------------位字段太长 Call of non-function -----------------调用未定义的函数 Call to function with no prototype ---------------调用函数时没有函数的说明 Cannot modify a const object ---------------不允许修改常量对象 Case outside of switch ----------------漏掉了case 语句 Case syntax error ------------------ Case 语法错误 Code has no effect -----------------代码不可述不可能执行到 Compound statement missing{ --------------------分程序漏掉"{" Conflicting type modifiers ------------------不明确的类型说明符 Constant expression required ----------------要求常量表达式 Constant out of range in comparison -----------------在比较常量超出范围 Conversion may lose significant digits -----------------转换时会丢失意义的数字 Conversion of near pointer not allowed -----------------不允许转换近指针 Could not find file ''xxx'' -----------------------找不到XXX文件 Declaration missing ; ----------------说明缺少";" houjiuming Declaration syntax error -----------------说明出现语法错误 Default outside of switch ------------------ Default 出现在switch语句之外 Define directive needs an identifier ------------------定义编译预处理需要标识符 Division by zero ------------------用零作除数 Do statement must have while ------------------ Do-while语句缺少while部分 Enum syntax error ---------------------枚举类型语法错误 Enumeration constant syntax error -----------------枚举常数语法错误 Error directive :xxx ------------------------错误的编译预处理命令 Error writing output file ---------------------写输出文件错误 Expression syntax error -----------------------表达式语法错误 Extra parameter in call ------------------------调用时出现多余错误 File name too long ----------------文件名太长 Function call missing -----------------函数调用缺少右括号 Fuction definition out of place ------------------函数定义位置错误 Fuction should return a value ------------------函数必需返回一个值 Goto statement missing label ------------------ Goto语句没有标号 Hexadecimal or octal constant too large ------------------16进制或8进制常数太大 Illegal character ''x'' ------------------非法字符x Illegal initialization ------------------非法的初始化 Illegal octal digit ------------------非法的8进制数字 houjiuming Illegal pointer subtraction ------------------非法的指针相减 Illegal structure operation ------------------非法的结构体操作 Illegal use of floating point -----------------非法的浮点运算 Illegal use of pointer --------------------指针使用非法 Improper use of a typedefsymbol ----------------类型定义符号使用不恰当 In-line assembly not allowed -----------------不允许使用行间汇编 Incompatible storage class -----------------存储类别不相容 Incompatible type conversion --------------------不相容的类型转换 Incorrect number format -----------------------错误的数据格式 Incorrect use of default --------------------- Default使用不当 Invalid indirection ---------------------无效的间接运算 Invalid pointer addition ------------------指针相加无效 Irreducible expression tree -----------------------无法执行的表达式运算 Lvalue required ---------------------------需要逻辑值0或非0值 Macro argument syntax error -------------------宏参数语法错误 Macro expansion too long ----------------------宏的扩展以后太长 Mismatched number of parameters in definition ---------------------定义参数个数不匹配 Misplaced break ---------------------此处不应出现break语句 Misplaced continue ------------------------此处不应出现continue语句 Misplaced decimal point --------------------此处不应出现小数点 Misplaced elif directive --------------------不应编译预处理elif Misplaced else ----------------------此处不应出现else houjiuming Misplaced else directive ------------------此处不应出现编译预处理else Misplaced endif directive -------------------此处不应出现编译预处理endif Must be addressable ----------------------必须是可以编址的 Must take address of memory location ------------------必须存储定位的地址 No declaration for function ''xxx'' -------------------没有函数xxx的说明 No stack ---------------缺少堆栈 No type information ------------------没有类型信息 Non-portable pointer assignment --------------------不可移动的指针(地址常数)赋值 Non-portable pointer comparison --------------------不可移动的指针(地址常数)比较 Non-portable pointer conversion ----------------------不可移动的指针(地址常数)转换 Not a valid expression format type ---------------------不合法的表达式格式 Not an allowed type ---------------------不允许使用的类型 Numeric constant too large -------------------数值常太大 Out of memory -------------------内存不够用 houjiuming Parameter ''xxx'' is never used ------------------能数xxx没有用到 Pointer required on left side of -> -----------------------符号->的左边必须是指针 Possible use of ''xxx'' before definition -------------------在定义之前就使用了xxx(警告) Possibly incorrect assignment ----------------赋值可能不正确 Redeclaration of ''xxx'' -------------------重复定义了xxx Redefinition of ''xxx'' is not identical ------------------- xxx的两次定义不一致 Register allocation failure ------------------寄存器定址失败 Repeat count needs an lvalue ------------------重复计数需要逻辑值 Size of structure or array not known ------------------结构体或数给大小不确定 Statement missing ; ------------------语句后缺少";" Structure or union syntax error --------------结构体或联合体语法错误 Structure size too large ----------------结构体尺寸太大 Sub scripting missing ] ----------------下标缺少右方括号 Superfluous & with function or array ------------------函数或数组有多余的"&" Suspicious pointer conversion ---------------------可疑的指针转换 Symbol limit exceeded ---------------符号超限 Too few parameters in call -----------------函数调用时的实参少于函数的参数不 Too many default cases ------------------- Default太多(switch语句一个) Too many error or warning messages --------------------错误或警告信息太多 Too many type in declaration -----------------说明类型太多 houjiuming Too much auto memory in function -----------------函数用到的局部存储太多 Too much global data defined in file ------------------文件全局数据太多 Two consecutive dots -----------------两个连续的句点 Type mismatch in parameter xxx ----------------参数xxx类型不匹配 Type mismatch in redeclaration of ''xxx'' ---------------- xxx重定义的类型不匹配 Unable to create output file ''xxx'' ----------------无法建立输出文件xxx Unable to open include file ''xxx'' ---------------无法打开被包含的文件xxx Unable to open input file ''xxx'' ----------------无法打开输入文件xxx Undefined label ''xxx'' -------------------没有定义的标号xxx Undefined structure ''xxx'' -----------------没有定义的结构xxx Undefined symbol ''xxx'' -----------------没有定义的符号xxx Unexpected end of file in comment started on line xxx ----------从xxx行开始的注解尚未结束文件不能结束 Unexpected end of file in conditional started on line xxx ----从xxx 开始的条件语句尚未结束文件不能结束 Unknown assemble instruction ----------------未知的汇编结构 houjiuming Unknown option ---------------未知的操作 Unknown preprocessor directive: ''xxx'' -----------------不认识的预处理命令xxx Unreachable code ------------------无路可达的代码 Unterminated string or character constant -----------------字符串缺少引号 User break ----------------用户强行断了程序 Void functions may not return a value ----------------- Void类型的函数不应有返回值 Wrong number of arguments -----------------调用函数的参数数目错 ''xxx'' not an argument ----------------- xxx不是参数 ''xxx'' not part of structure -------------------- xxx不是结构体的一部分 xxx statement missing ( -------------------- xxx语句缺少左括号 xxx statement missing ) ------------------ xxx语句缺少右括号 xxx statement missing ; -------------------- xxx缺少分号 houjiuming xxx'' declared but never used -------------------说明了xxx但没有使用 xxx'' is assigned a value which is never used ----------------------给xxx赋了值但未用过 Zero length structure ------------------结构体的长度为零
Table of Contents Summary of GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Free software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Contributors to GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1 A Sample GDB Session . . . . . . . . . . . . . . . . . . . . 5 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9 1.10 2 Loading the Executable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting Display width. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running the executable under GDB . . . . . . . . . . . . . . . . . . . . . . Stepping to the next line in the source program . . . . . . . . . . . . Stepping into a subroutine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Examining the Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Printing Variable Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Listing Source Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting Variable Values During a Session . . . . . . . . . . . . . . . . . Getting In and Out of GDB . . . . . . . . . . . . . . . 11 2.1 Invoking GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.1 Choosing files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.2 Choosing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.1.3 Redirecting WDB input and output to a file . . . . . 2.2 Quitting GDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.3 Shell commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 5 6 6 6 6 6 7 7 7 8 11 11 13 15 15 16 GDB Commands . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.1 Command syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.2 Command completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 3.3 Getting help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 4 Running Programs Under GDB . . . . . . . . . . . 23 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8 4.9 4.10 Compiling for debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Starting your program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Arguments To Your Program. . . . . . . . . . . . . . . . . . . . . . . . . . . . Program Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Working directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Program Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Debugging a Running Process . . . . . . . . . . . . . . . . . . . . . . . . . . . Killing the child process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Debugging programs with multiple threads . . . . . . . . . . . . . . . Debugging programs with multiple processes . . . . . . . . . . . . 23 23 24 25 26 26 27 28 28 31 ii 5 Debugging with GDB Stopping and Continuing . . . . . . . . . . . . . . . . . . 33 5.1 Breakpoints. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.1 Setting breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.2 Setting catchpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.3 Deleting breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.4 Disabling breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.5 Break conditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.6 Breakpoint command lists . . . . . . . . . . . . . . . . . . . . . . 5.1.7 Breakpoint menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.1.8 “Cannot insert breakpoints” . . . . . . . . . . . . . . . . . . . . 5.2 Continuing and stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.3 Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4 Stopping and starting multi-thread programs . . . . . . . . . . . . . 6 Examining the Stack . . . . . . . . . . . . . . . . . . . . . . 51 6.1 6.2 6.3 6.4 6.5 6.6 7 Stack frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Stacks Without frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Commands for Examining the Stack . . . . . . . . . . . . . . . . . . . . . Backtraces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Selecting a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Information about a frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 51 52 52 53 54 Examining Source Files . . . . . . . . . . . . . . . . . . . 57 7.1 7.2 7.3 7.4 8 33 33 37 38 39 40 41 42 43 43 46 48 Printing source lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Searching source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Specifying source directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . Source and machine code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57 58 59 59 Examining Data . . . . . . . . . . . . . . . . . . . . . . . . . . 63 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 8.10 8.11 8.12 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Program variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Artificial arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Output formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Examining memory. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Automatic display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Print settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Value history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Convenience variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Printing Floating Point Values . . . . . . . . . . . . . . . . . . . . . . . . . Floating point hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 64 65 66 67 68 70 74 75 76 78 78 iii 9 Using GDB with Different Languages . . . . . . 79 9.1 Switching between source languages . . . . . . . . . . . . . . . . . . . . . 9.1.1 List of filename extensions and languages . . . . . . . . 9.1.2 Setting the working language . . . . . . . . . . . . . . . . . . . 9.1.3 Having GDB infer the source language . . . . . . . . . . 9.2 Displaying the language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3 Type and range checking. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.3.1 An overview of type checking . . . . . . . . . . . . . . . . . . . 9.3.2 An overview of range checking . . . . . . . . . . . . . . . . . . 9.4 Supported languages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.4.1 C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.4.1.1 C and C++ operators . . . . . . . . . . . . . . . . . . 9.4.1.2 C and C++ constants . . . . . . . . . . . . . . . . . . 9.4.1.3 C++ expressions . . . . . . . . . . . . . . . . . . . . . . . 9.4.1.4 C and C++ defaults . . . . . . . . . . . . . . . . . . . 9.4.1.5 C and C++ type and range checks . . . . . . 9.4.1.6 GDB and C . . . . . . . . . . . . . . . . . . . . . . . . . . 9.4.1.7 GDB features for C++ . . . . . . . . . . . . . . . . . 9.4.2 Fortran . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.4.2.1 Fortran types . . . . . . . . . . . . . . . . . . . . . . . . . 9.4.2.2 Fortran operators . . . . . . . . . . . . . . . . . . . . . 9.4.2.3 Fortran special issues . . . . . . . . . . . . . . . . . . 79 79 80 80 80 81 81 82 83 83 84 85 86 87 88 88 88 89 90 90 91 10 Examining the Symbol Table . . . . . . . . . . . . . 93 11 Altering Execution . . . . . . . . . . . . . . . . . . . . . . 97 11.1 11.2 11.3 11.4 11.5 11.6 12 Assignment to variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97 Continuing at a different address . . . . . . . . . . . . . . . . . . . . . . . 98 Giving your program a signal . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Returning from a function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Calling program functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 Patching programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 GDB Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 12.1 Commands to specify files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103 12.2 Specifying shared library locations . . . . . . . . . . . . . . . . . . . . . 106 12.3 Errors reading symbol files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 13 Specifying a Debugging Target . . . . . . . . . . 109 13.1 Active targets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 13.2 Commands for managing targets . . . . . . . . . . . . . . . . . . . . . . 109 13.3 Choosing target byte order. . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 iv 14 Debugging with GDB HP-UX Configuration-Specific Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 14.1 Summary of HP Enhancements to GDB . . . . . . . . . . . . . . . 113 14.2 HP-UX dependencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 14.2.1 Linker Dependencies . . . . . . . . . . . . . . . . . . . . . . . . . 115 14.2.2 Dependent Standard Library Routines for Run Time Checking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116 14.3 Supported Platforms and Modes . . . . . . . . . . . . . . . . . . . . . . 117 14.4 HP-UX targets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 14.5 Support for Alternate root . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 14.6 Specifying object file directories . . . . . . . . . . . . . . . . . . . . . . . 118 14.7 Fix and continue debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . 120 14.7.1 Fix and Continue compiler dependencies . . . . . . 120 14.7.2 Fix and Continue restrictions . . . . . . . . . . . . . . . . . 121 14.7.3 Using Fix and Continue . . . . . . . . . . . . . . . . . . . . . . 121 14.7.4 Example Fix and Continue session . . . . . . . . . . . . 122 14.8 Inline Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 14.8.1 Inline Debugging in HP 9000 Systems . . . . . . . . . 124 14.8.2 Inline Debugging in Integrity Systems . . . . . . . . . 125 14.8.2.1 Debugging Inline Functions in Integrity Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126 14.9 Debugging memory problems . . . . . . . . . . . . . . . . . . . . . . . . . 128 14.9.1 When to suspect a memory leak . . . . . . . . . . . . . . 128 14.9.2 Memory debugging restrictions . . . . . . . . . . . . . . . 128 14.9.3 Memory Debugging Methodologies . . . . . . . . . . . . 128 14.9.4 Debugging Memory in Interactive Mode . . . . . . . 129 14.9.4.1 Commands for interactive memory debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129 14.9.4.2 Example for interactive debugging session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 14.9.5 Debugging Memory in Batch Mode . . . . . . . . . . . 133 14.9.5.1 Setting Configuration Options for Batch Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133 14.9.5.2 Environment variable setting for Batch mode debugging . . . . . . . . . . . . . . . . . . . . . . . . . 134 14.9.5.3 Example for Batch Mode RTC . . . . . . . 135 14.9.6 Debugging Memory Interactively After Attaching to a Running Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 14.9.7 Configuring memory debugging settings . . . . . . . 137 14.9.7.1 Specifying the stack depth . . . . . . . . . . . 137 14.9.7.2 Specifying minimum leak size . . . . . . . . 138 14.9.7.3 Specifying minimum block size . . . . . . . 138 14.9.8 Scenarios in memory debugging . . . . . . . . . . . . . . . 138 14.9.8.1 Stop when freeing unallocated or deallocated blocks . . . . . . . . . . . . . . . . . . . . . . . 138 14.9.8.2 Stop when freeing a block if bad writes occurred outside block boundary . . . . . . . . . . 138 v 14.9.8.3 Stop when a specified block address is allocated or deallocated . . . . . . . . . . . . . . . . . . 139 14.9.8.4 Scramble previous memory contents at malloc/free calls . . . . . . . . . . . . . . . . . . . . . . . . . 139 14.9.9 Comparison of Memory Debugging Commands in Interactive Mode and Batch Mode . . . . . . . . . . . . . . . 140 14.9.10 Heap Profiling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142 14.9.10.1 Commands for heap profiling . . . . . . . 142 14.9.10.2 info heap arena . . . . . . . . . . . . . . . . . . 143 14.9.10.3 info heap arena [0 |1|2|..] blocks stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 14.9.10.4 info module ADDRESS . . . . . . . . . . . . . . 143 14.9.10.5 info heap process . . . . . . . . . . . . . . . . 143 14.9.10.6 Example for heap profiling . . . . . . . . . . 143 14.9.11 Memory Checking Analysis for User Defined Memory Management Routines . . . . . . . . . . . . . . . . . . 144 14.9.12 Commands to track the change in data segment value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 14.10 Thread Debugging Support . . . . . . . . . . . . . . . . . . . . . . . . . . 145 14.10.1 Support for Enabling and Disabling Specific Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 14.10.2 Backtrace Support for Thread Debugging . . . . 146 14.10.3 Advanced Thread Debugging Support . . . . . . . . 146 14.10.3.1 Pre-requisites for Advanced Thread Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 14.10.3.2 Enabling and Disabling Advanced Thread Debugging Features. . . . . . . . . . . . . . . 148 14.10.3.3 Commands to view information on pthread primitives . . . . . . . . . . . . . . . . . . . . . . . 150 14.11 Debugging MPI Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . 150 14.12 Debugging multiple processes ( programs with fork and vfork calls) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151 14.12.1 Ask mode for set follow-fork-mode . . . . . . . . 151 14.12.2 serial mode for set follow-fork-mode . . . . . . . 151 14.12.3 Support for showing unwind info. . . . . . . . . . . . . 151 14.12.4 Printing CFM and PFS registers. . . . . . . . . . . . . 152 14.13 Debugging Core Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 14.13.1 Generating core files with packcore /unpackcore/getcore . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152 14.13.2 Support for the dumpcore command . . . . . . . . . 153 14.13.2.1 Enhancements to the dumpcore command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 14.14 Invoking GDB Before a Program Aborts . . . . . . . . . . . . . . 154 14.15 Instruction Level Stepping . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 14.16 Enhanced support for watchpoints and breakpoints . . . . 155 14.16.1 Deferred watchpoints . . . . . . . . . . . . . . . . . . . . . . . 155 14.16.2 Hardware watchpoints . . . . . . . . . . . . . . . . . . . . . . 155 14.16.3 Hardware breakpoints . . . . . . . . . . . . . . . . . . . . . . 155 vi Debugging with GDB 14.17 14.18 14.19 14.20 14.21 14.22 14.23 14.16.3.1 Setting breakpoints in unstripped shared library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 14.16.4 Support for procedural breakpoints . . . . . . . . . . 155 14.16.5 Support for template breakpoints . . . . . . . . . . . . 156 Debugging support for shared libraries . . . . . . . . . . . . . . . . 156 14.17.1 Using shared library as main program . . . . . . . . 157 14.17.2 Setting Deferred Breakpoints in Shared Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 14.17.3 Using catch load . . . . . . . . . . . . . . . . . . . . . . . . . . 158 14.17.4 Privately mapping shared libraries . . . . . . . . . . . 158 14.17.5 Selectively Mapping Shared Libraries As Private . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 14.17.6 Setting breakpoints in shared library . . . . . . . . . 159 Language support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 14.18.1 Enhanced Java Debugging Support . . . . . . . . . . 159 14.18.2 Commands for Examining Java Virtual Machine(JVM) internals . . . . . . . . . . . . . . . . . . . . . . . . . 159 14.18.2.1 Java subcommands . . . . . . . . . . . . . . . . 160 14.18.3 Support for stack traces in Java, C, and C++ programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160 14.18.4 Support for 64-bit Java, C, aC++ stack unwinding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 14.18.5 Enhanced support for C++ templates . . . . . . . . . 161 14.18.6 Support for __fpreg data type on IPF . . . . . . . 162 14.18.7 Support for Complex variables in HP C . . . . . 162 14.18.8 Support for debugging namespaces . . . . . . . . . . . 163 14.18.9 Command for evaluating the address of an expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163 Viewing Wide Character Strings . . . . . . . . . . . . . . . . . . . . . 163 Support for output logging . . . . . . . . . . . . . . . . . . . . . . . . . . . 164 14.20.1 Support for dumping array in an ASCII file . . 164 14.20.2 Support for Fortran array slices . . . . . . . . . . . . . . 165 14.20.3 Displaying enumerators . . . . . . . . . . . . . . . . . . . . . 165 14.20.4 Support for debugging typedefs . . . . . . . . . . . . . . 165 14.20.5 Support for steplast command for C and C++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Getting information from a non-debug executable . . . . . 166 Debugging optimized code . . . . . . . . . . . . . . . . . . . . . . . . . . . 167 14.22.1 Debugging Optimized Code at Various Optimization Levels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 14.22.1.1 +O0 and +O1 . . . . . . . . . . . . . . . . . . . . . . . 169 14.22.1.2 +O2 and +O3 . . . . . . . . . . . . . . . . . . . . . . . 169 14.22.1.3 +O4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169 Visual Interface for WDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 14.23.1 Starting and stopping Visual Interface for WDB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170 14.23.2 Navigating the Visual Interface for WDB display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171 vii 14.23.3 Specifying foreground and background colors . . 172 14.23.4 Using the X-window graphical interface . . . . . . 173 14.23.5 Using the TUI mode . . . . . . . . . . . . . . . . . . . . . . . . 173 14.23.6 Changing the size of the source or debugger pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 14.23.7 Using commands to browse through source files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174 14.23.8 Loading source files . . . . . . . . . . . . . . . . . . . . . . . . . 175 14.23.9 Editing source files . . . . . . . . . . . . . . . . . . . . . . . . . 175 14.23.10 Editing the command line and command-line history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 14.23.11 Saving the contents of a debugging session to a file. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175 14.24 Support for ddd. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 14.25 Support for XDB commands . . . . . . . . . . . . . . . . . . . . . . . . . 176 14.25.1 stop in/at dbx commands . . . . . . . . . . . . . . . . . . . 176 14.26 GNU GDB Logging Commands . . . . . . . . . . . . . . . . . . . . . . 176 14.27 Support for command line calls in a stripped executable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176 14.27.1 Support for command line calls in a stripped executable on PA-RISC systems . . . . . . . . . . . . . . . . . 176 14.27.2 Additional support for command line calls in a stripped executable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 14.27.2.1 For 32-bit applications: . . . . . . . . . . . . . 177 14.27.2.2 For 64-bit applications . . . . . . . . . . . . . 177 14.27.3 Support for debugging stripped binaries . . . . . . 178 14.27.3.1 Printing of locals and globals in a stripped module . . . . . . . . . . . . . . . . . . . . . . . . . 178 14.27.3.2 Backtrace on stripped frames . . . . . . . 178 14.27.3.3 Command line calls to non-stripped library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 14.27.3.4 Setting breakpoints in unstripped shared library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178 14.28 Displaying the current block scope information . . . . . . . . 178 14.29 Linux support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 15 The HP-UX Terminal User Interface. . . . . 181 15.1 Starting the TUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.2 Automatically running a program at startup . . . . . . . . . . . 15.3 Screen Layouts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.3.1 Source pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.3.2 Disassembly pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.3.3 Source/Disassembly pane . . . . . . . . . . . . . . . . . . . . 15.3.4 Disassembly/Register pane . . . . . . . . . . . . . . . . . . . 15.3.5 Source/Register pane . . . . . . . . . . . . . . . . . . . . . . . . 15.4 Cycling through the panes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.5 Changing pane focus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15.6 Scrolling panes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 182 183 183 183 184 185 186 187 187 190 viii Debugging with GDB 15.7 Changing the register display . . . . . . . . . . . . . . . . . . . . . . . . . 190 15.8 Changing the pane size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192 15.9 Refreshing and updating the window . . . . . . . . . . . . . . . . . . 193 16 XDB to WDB Transition Guide . . . . . . . . . 195 16.1 By-function lists of XDB commands and HP WDB equivalents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195 16.1.1 Invocation commands . . . . . . . . . . . . . . . . . . . . . . . . 196 16.1.2 Window mode commands . . . . . . . . . . . . . . . . . . . . 196 16.1.3 File viewing commands . . . . . . . . . . . . . . . . . . . . . . 197 16.1.4 Source directory mapping commands . . . . . . . . . . 198 16.1.5 Data Viewing and modification commands. . . . . 199 16.1.6 Stack viewing commands . . . . . . . . . . . . . . . . . . . . . 201 16.1.7 Status-viewing command . . . . . . . . . . . . . . . . . . . . . 201 16.1.8 Job control commands . . . . . . . . . . . . . . . . . . . . . . . 202 16.2 Overall breakpoint commands . . . . . . . . . . . . . . . . . . . . . . . . . 203 16.2.1 Auxiliary breakpoint commands . . . . . . . . . . . . . . 203 16.2.2 Breakpoint creation commands . . . . . . . . . . . . . . . 204 16.2.3 Breakpoint status commands . . . . . . . . . . . . . . . . . 205 16.2.4 All-procedures breakpoint commands . . . . . . . . . 206 16.2.5 Global breakpoint commands . . . . . . . . . . . . . . . . . 207 16.2.6 Assertion control commands . . . . . . . . . . . . . . . . . . 207 16.2.7 Record and playback commands . . . . . . . . . . . . . . 207 16.2.8 Macro facility commands . . . . . . . . . . . . . . . . . . . . . 208 16.2.9 Signal control commands . . . . . . . . . . . . . . . . . . . . . 208 16.2.10 Miscellaneous commands . . . . . . . . . . . . . . . . . . . . 209 16.3 XDB data formats and HP WDB equivalents . . . . . . . . . . . 210 16.4 XDB location syntax and HP WDB equivalents . . . . . . . . 212 16.5 XDB special language operators and HP WDB equivalents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 16.6 XDB special variables and HP WDB equivalents. . . . . . . . 213 16.7 XDB variable identifiers and HP WDB equivalents. . . . . . 215 16.8 Alphabetical lists of XDB commands and HP WDB equivalents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215 16.8.1 A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 16.8.2 B . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 216 16.8.3 C through D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218 16.8.4 F through K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 16.8.5 L . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 220 16.8.6 M through P . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221 16.8.7 Q through S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222 16.8.8 T . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 16.8.9 U through Z . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224 16.8.10 Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226 ix 17 Controlling GDB . . . . . . . . . . . . . . . . . . . . . . . 231 17.1 17.2 17.3 17.4 17.5 17.6 17.7 18 Setting the GDB Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Setting Command Editing Options in GDB . . . . . . . . . . . . Setting Command History Feature in GDB . . . . . . . . . . . . . Setting the GDB Screen Size . . . . . . . . . . . . . . . . . . . . . . . . . . Supported Number Formats. . . . . . . . . . . . . . . . . . . . . . . . . . . Optional warnings and messages . . . . . . . . . . . . . . . . . . . . . . Optional messages about internal happenings. . . . . . . . . . . 231 231 231 233 233 234 235 Canned Sequences of Commands . . . . . . . . 237 18.1 18.2 18.3 18.4 User-defined commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . User-defined command hooks . . . . . . . . . . . . . . . . . . . . . . . . . Command files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Commands for controlled output . . . . . . . . . . . . . . . . . . . . . . 237 238 239 239 19 Using GDB under gnu Emacs . . . . . . . . . . . 241 20 GDB Annotations . . . . . . . . . . . . . . . . . . . . . . 243 20.1 20.2 20.3 20.4 20.5 20.6 20.7 20.8 20.9 20.10 20.11 20.12 21 What is an annotation? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . The server prefix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Values. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Annotation for GDB input . . . . . . . . . . . . . . . . . . . . . . . . . . . . Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Information on breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . Invalidation notices. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Running the program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Displaying source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Annotations We Might Want in the Future . . . . . . . . . . . . 243 243 244 245 246 247 247 248 248 249 249 250 The gdb/mi Interface . . . . . . . . . . . . . . . . . . . 251 Function and purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Notation and terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.1 gdb/mi Command Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.1.1 gdb/mi Input syntax . . . . . . . . . . . . . . . . . . . . . . . . 21.1.2 gdb/mi Output syntax . . . . . . . . . . . . . . . . . . . . . . 21.1.3 Simple examples of gdb/mi interaction . . . . . . . . 21.2 gdb/mi compatibility with CLI . . . . . . . . . . . . . . . . . . . . . . . 21.3 gdb/mi output records . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.3.1 gdb/mi result records . . . . . . . . . . . . . . . . . . . . . . . 21.3.2 gdb/mi stream records . . . . . . . . . . . . . . . . . . . . . . 21.3.3 gdb/mi out-of-band records . . . . . . . . . . . . . . . . . . 21.4 gdb/mi command description format . . . . . . . . . . . . . . . . . . 21.5 gdb/mi breakpoint table commands . . . . . . . . . . . . . . . . . . . 21.6 gdb/mi Data manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.7 gdb/mi program control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251 251 251 251 252 254 254 255 255 255 255 256 257 265 275 x Debugging with GDB 21.8 21.9 21.10 21.11 21.12 21.13 21.14 22 Miscellaneous GDB commands in gdb/mi. . . . . . . . . . . . . . gdb/mi Stack Manipulation Commands . . . . . . . . . . . . . . . gdb/mi Symbol query commands . . . . . . . . . . . . . . . . . . . . gdb/mi Target Manipulation Commands . . . . . . . . . . . . . gdb/mi thread commands . . . . . . . . . . . . . . . . . . . . . . . . . . . gdb/mi tracepoint commands . . . . . . . . . . . . . . . . . . . . . . . . gdb/mi variable objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286 288 293 296 301 303 303 Reporting Bugs in GDB . . . . . . . . . . . . . . . . 309 22.1 Have you found a bug? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 22.2 How to report bugs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309 Appendix A Installing GDB . . . . . . . . . . . . . . . . 313 A.1 Compiling GDB in another directory . . . . . . . . . . . . . . . . . . . 314 A.2 Specifying names for hosts and targets . . . . . . . . . . . . . . . . . 315 A.3 configure options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 316 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
### 回答1: 这个错误提示是因为你试图将一个数组类型的表达式赋值给一个变量。在C语言,数组是一种特殊的数据类型,它们不能像普通变量一样直接赋值。如果你想给数组赋值,需要使用循环或者数组初始化语法来逐个赋值。 例如,下面的代码会导致这个错误: ``` int arr[5]; arr = {1, 2, 3, 4, 5}; // 错误:不能将数组赋值给表达式 ``` 正确的做法是使用循环或者数组初始化语法: ``` int arr[5]; for (int i = ; i < 5; i++) { arr[i] = i + 1; } // 或者使用数组初始化语法 int arr[5] = {1, 2, 3, 4, 5}; ``` ### 回答2: 该错误指的是将一个数组类型的表达式赋值给一个变量,这是不合法的。 在C语言,数组是一组相同类型的元素的集合,这些元素在内存是连续存储的。而表达式则是可以求值的计算式。当我们将一个数组类型的表达式进行赋值时,就会发生上述错误。 例如,如果有一个整型数组a,我们不能将它作为一个整型类型的变量来赋值,如下所示: int a[5] = {1, 2, 3, 4, 5}; int b = a; // 错误:assignment to expression with array type 需要注意的是,可以将数组名作为一个指向数组首元素的指针来进行赋值。如下所示: int a[5] = {1, 2, 3, 4, 5}; int *b = a; // 正确,b指向数组a的首元素 此外,在函数调用也容易出现该错误。当我们使用一个数组名作为函数的参数时,该数组名将被转换为指向数组首元素的指针。但是在函数,我们不能直接将这个指针赋值给一个数组类型的变量,否则也会出现上述错误。 总之,在C语言,应该始终记住数组和指针的区别,避免在程序出现上述错误。 ### 回答3: 这个错误消息意味着你正在尝试给一个数组表达式赋值,而数组不是一个可被赋值的对象。这通常是由于数学运算符被错误地用于数组上,或者由于尝试使用赋值运算符在数组上进行修改所导致的。 例如,以下代码会导致“assignment to expression with array type”错误: int arr[5]; arr = {1, 2, 3, 4, 5}; // 尝试用花括号形式对数组进行赋值 另一个例子是以下代码会导致同样的错误: int arr1[5], arr2[5]; arr1 = arr2; // 尝试将一个数组赋值给另一个数组 要解决这个错误,需要检查代码的语法错误或逻辑错误,并确保没有使用运算符来处理数组。如果你需要将一个数组的值复制到另一个数组,可以使用一个循环来逐个复制每一个元素。例如: int arr1[5], arr2[5]; for(int i=0; i<5; i++) { arr1[i] = arr2[i]; } 总之,要避免错误消息“assignment to expression with array type ”,你应该记住,数组不能直接进行赋值,只能使用循环逐个赋值。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值