1/*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2005-2007, Joseph Koshy 5 * Copyright (c) 2007 The FreeBSD Foundation 6 * All rights reserved. 7 * 8 * Portions of this software were developed by A. Joseph Koshy under 9 * sponsorship from the FreeBSD Foundation and Google, Inc. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 */ 32 33/* 34 * Transform a hwpmc(4) log into human readable form, and into 35 * gprof(1) compatible profiles. 36 */ 37 38#include <sys/cdefs.h> 39__FBSDID("$FreeBSD: stable/11/usr.sbin/pmcstat/pmcpl_callgraph.c 330449 2018-03-05 07:26:05Z eadler $"); 40 41#include <sys/param.h> 42#include <sys/endian.h> 43#include <sys/gmon.h> 44#include <sys/imgact_aout.h> 45#include <sys/imgact_elf.h> 46#include <sys/mman.h> 47#include <sys/pmc.h> 48#include <sys/queue.h> 49#include <sys/socket.h> 50#include <sys/stat.h> 51#include <sys/wait.h> 52 53#include <netinet/in.h> 54 55#include <assert.h> 56#include <curses.h> 57#include <err.h> 58#include <errno.h> 59#include <fcntl.h> 60#include <gelf.h> 61#include <libgen.h> 62#include <limits.h> 63#include <netdb.h> 64#include <pmc.h> 65#include <pmclog.h> 66#include <sysexits.h> 67#include <stdint.h> 68#include <stdio.h> 69#include <stdlib.h> 70#include <string.h> 71#include <unistd.h> 72 73#include "pmcstat.h" 74#include "pmcstat_log.h" 75#include "pmcstat_top.h" 76#include "pmcpl_callgraph.h" 77 78/* Get the sample value in percent related to nsamples. */ 79#define PMCPL_CG_COUNTP(a) \ 80 ((a)->pcg_count * 100.0 / nsamples) 81 82/* 83 * The toplevel CG nodes (i.e., with rank == 0) are placed in a hash table. 84 */ 85 86struct pmcstat_cgnode_hash_list pmcstat_cgnode_hash[PMCSTAT_NHASH]; 87int pmcstat_cgnode_hash_count; 88 89static pmcstat_interned_string pmcstat_previous_filename_printed; 90 91static struct pmcstat_cgnode * 92pmcstat_cgnode_allocate(struct pmcstat_image *image, uintfptr_t pc) 93{ 94 struct pmcstat_cgnode *cg; 95 96 if ((cg = malloc(sizeof(*cg))) == NULL) 97 err(EX_OSERR, "ERROR: Cannot allocate callgraph node"); 98 99 cg->pcg_image = image; 100 cg->pcg_func = pc; 101 102 cg->pcg_count = 0; 103 cg->pcg_nchildren = 0; 104 LIST_INIT(&cg->pcg_children); 105 106 return (cg); 107} 108 109/* 110 * Free a node and its children. 111 */ 112static void 113pmcstat_cgnode_free(struct pmcstat_cgnode *cg) 114{ 115 struct pmcstat_cgnode *cgc, *cgtmp; 116 117 LIST_FOREACH_SAFE(cgc, &cg->pcg_children, pcg_sibling, cgtmp) 118 pmcstat_cgnode_free(cgc); 119 free(cg); 120} 121 122/* 123 * Look for a callgraph node associated with pmc `pmcid' in the global 124 * hash table that corresponds to the given `pc' value in the process 125 * `pp'. 126 */ 127static struct pmcstat_cgnode * 128pmcstat_cgnode_hash_lookup_pc(struct pmcstat_process *pp, pmc_id_t pmcid, 129 uintfptr_t pc, int usermode) 130{ 131 struct pmcstat_pcmap *ppm; 132 struct pmcstat_symbol *sym; 133 struct pmcstat_image *image; 134 struct pmcstat_cgnode *cg; 135 struct pmcstat_cgnode_hash *h; 136 uintfptr_t loadaddress; 137 unsigned int i, hash; 138 139 ppm = pmcstat_process_find_map(usermode ? pp : pmcstat_kernproc, pc); 140 if (ppm == NULL) 141 return (NULL); 142 143 image = ppm->ppm_image; 144 145 loadaddress = ppm->ppm_lowpc + image->pi_vaddr - image->pi_start; 146 pc -= loadaddress; /* Convert to an offset in the image. */ 147 148 /* 149 * Try determine the function at this offset. If we can't 150 * find a function round leave the `pc' value alone. 151 */ 152 if ((sym = pmcstat_symbol_search(image, pc)) != NULL) 153 pc = sym->ps_start; 154 else 155 pmcstat_stats.ps_samples_unknown_function++; 156 157 for (hash = i = 0; i < sizeof(uintfptr_t); i++) 158 hash += (pc >> i) & 0xFF; 159 160 hash &= PMCSTAT_HASH_MASK; 161 162 cg = NULL; 163 LIST_FOREACH(h, &pmcstat_cgnode_hash[hash], pch_next) 164 { 165 if (h->pch_pmcid != pmcid) 166 continue; 167 168 cg = h->pch_cgnode; 169 170 assert(cg != NULL); 171 172 if (cg->pcg_image == image && cg->pcg_func == pc) 173 return (cg); 174 } 175 176 /* 177 * We haven't seen this (pmcid, pc) tuple yet, so allocate a 178 * new callgraph node and a new hash table entry for it. 179 */ 180 cg = pmcstat_cgnode_allocate(image, pc); 181 if ((h = malloc(sizeof(*h))) == NULL) 182 err(EX_OSERR, "ERROR: Could not allocate callgraph node"); 183 184 h->pch_pmcid = pmcid; 185 h->pch_cgnode = cg; 186 LIST_INSERT_HEAD(&pmcstat_cgnode_hash[hash], h, pch_next); 187 188 pmcstat_cgnode_hash_count++; 189 190 return (cg); 191} 192 193/* 194 * Compare two callgraph nodes for sorting. 195 */ 196static int 197pmcstat_cgnode_compare(const void *a, const void *b) 198{ 199 const struct pmcstat_cgnode *const *pcg1, *const *pcg2, *cg1, *cg2; 200 201 pcg1 = (const struct pmcstat_cgnode *const *) a; 202 cg1 = *pcg1; 203 pcg2 = (const struct pmcstat_cgnode *const *) b; 204 cg2 = *pcg2; 205 206 /* Sort in reverse order */ 207 if (cg1->pcg_count < cg2->pcg_count) 208 return (1); 209 if (cg1->pcg_count > cg2->pcg_count) 210 return (-1); 211 return (0); 212} 213 214/* 215 * Find (allocating if a needed) a callgraph node in the given 216 * parent with the same (image, pcoffset) pair. 217 */ 218 219static struct pmcstat_cgnode * 220pmcstat_cgnode_find(struct pmcstat_cgnode *parent, struct pmcstat_image *image, 221 uintfptr_t pcoffset) 222{ 223 struct pmcstat_cgnode *child; 224 225 LIST_FOREACH(child, &parent->pcg_children, pcg_sibling) { 226 if (child->pcg_image == image && 227 child->pcg_func == pcoffset) 228 return (child); 229 } 230 231 /* 232 * Allocate a new structure. 233 */ 234 235 child = pmcstat_cgnode_allocate(image, pcoffset); 236 237 /* 238 * Link it into the parent. 239 */ 240 LIST_INSERT_HEAD(&parent->pcg_children, child, pcg_sibling); 241 parent->pcg_nchildren++; 242 243 return (child); 244} 245 246/* 247 * Print one callgraph node. The output format is: 248 * 249 * indentation %(parent's samples) #nsamples function@object 250 */ 251static void 252pmcstat_cgnode_print(struct pmcstat_cgnode *cg, int depth, uint32_t total) 253{ 254 uint32_t n; 255 const char *space; 256 struct pmcstat_symbol *sym; 257 struct pmcstat_cgnode **sortbuffer, **cgn, *pcg; 258 259 space = " "; 260 261 if (depth > 0) 262 (void) fprintf(args.pa_graphfile, "%*s", depth, space); 263 264 if (cg->pcg_count == total) 265 (void) fprintf(args.pa_graphfile, "100.0%% "); 266 else 267 (void) fprintf(args.pa_graphfile, "%05.2f%% ", 268 100.0 * cg->pcg_count / total); 269 270 n = fprintf(args.pa_graphfile, " [%u] ", cg->pcg_count); 271 272 /* #samples is a 12 character wide field. */ 273 if (n < 12) 274 (void) fprintf(args.pa_graphfile, "%*s", 12 - n, space); 275 276 if (depth > 0) 277 (void) fprintf(args.pa_graphfile, "%*s", depth, space); 278 279 sym = pmcstat_symbol_search(cg->pcg_image, cg->pcg_func); 280 if (sym) 281 (void) fprintf(args.pa_graphfile, "%s", 282 pmcstat_string_unintern(sym->ps_name)); 283 else 284 (void) fprintf(args.pa_graphfile, "%p", 285 (void *) (cg->pcg_image->pi_vaddr + cg->pcg_func)); 286 287 if (pmcstat_previous_filename_printed != 288 cg->pcg_image->pi_fullpath) { 289 pmcstat_previous_filename_printed = cg->pcg_image->pi_fullpath; 290 (void) fprintf(args.pa_graphfile, " @ %s\n", 291 pmcstat_string_unintern( 292 pmcstat_previous_filename_printed)); 293 } else 294 (void) fprintf(args.pa_graphfile, "\n"); 295 296 if (cg->pcg_nchildren == 0) 297 return; 298 299 if ((sortbuffer = (struct pmcstat_cgnode **) 300 malloc(sizeof(struct pmcstat_cgnode *) * 301 cg->pcg_nchildren)) == NULL) 302 err(EX_OSERR, "ERROR: Cannot print callgraph"); 303 cgn = sortbuffer; 304 305 LIST_FOREACH(pcg, &cg->pcg_children, pcg_sibling) 306 *cgn++ = pcg; 307 308 assert(cgn - sortbuffer == (int) cg->pcg_nchildren); 309 310 qsort(sortbuffer, cg->pcg_nchildren, sizeof(struct pmcstat_cgnode *), 311 pmcstat_cgnode_compare); 312 313 for (cgn = sortbuffer, n = 0; n < cg->pcg_nchildren; n++, cgn++) 314 pmcstat_cgnode_print(*cgn, depth+1, cg->pcg_count); 315 316 free(sortbuffer); 317} 318 319/* 320 * Record a callchain. 321 */ 322 323void 324pmcpl_cg_process(struct pmcstat_process *pp, struct pmcstat_pmcrecord *pmcr, 325 uint32_t nsamples, uintfptr_t *cc, int usermode, uint32_t cpu) 326{ 327 uintfptr_t pc, loadaddress; 328 uint32_t n; 329 struct pmcstat_image *image; 330 struct pmcstat_pcmap *ppm; 331 struct pmcstat_symbol *sym; 332 struct pmcstat_cgnode *parent, *child; 333 struct pmcstat_process *km; 334 pmc_id_t pmcid; 335 336 (void) cpu; 337 338 /* 339 * Find the callgraph node recorded in the global hash table 340 * for this (pmcid, pc). 341 */ 342 343 pc = cc[0]; 344 pmcid = pmcr->pr_pmcid; 345 parent = pmcstat_cgnode_hash_lookup_pc(pp, pmcid, pc, usermode); 346 if (parent == NULL) { 347 pmcstat_stats.ps_callchain_dubious_frames++; 348 pmcr->pr_dubious_frames++; 349 return; 350 } 351 352 parent->pcg_count++; 353 354 /* 355 * For each return address in the call chain record, subject 356 * to the maximum depth desired. 357 * - Find the image associated with the sample. Stop if there 358 * there is no valid image at that address. 359 * - Find the function that overlaps the return address. 360 * - If found: use the start address of the function. 361 * If not found (say an object's symbol table is not present or 362 * is incomplete), round down to th gprof bucket granularity. 363 * - Convert return virtual address to an offset in the image. 364 * - Look for a child with the same {offset,image} tuple, 365 * inserting one if needed. 366 * - Increment the count of occurrences of the child. 367 */ 368 km = pmcstat_kernproc; 369 370 for (n = 1; n < (uint32_t) args.pa_graphdepth && n < nsamples; n++, 371 parent = child) { 372 pc = cc[n]; 373 374 ppm = pmcstat_process_find_map(usermode ? pp : km, pc); 375 if (ppm == NULL) { 376 /* Detect full frame capture (kernel + user). */ 377 if (!usermode) { 378 ppm = pmcstat_process_find_map(pp, pc); 379 if (ppm != NULL) 380 km = pp; 381 } 382 } 383 if (ppm == NULL) 384 return; 385 386 image = ppm->ppm_image; 387 loadaddress = ppm->ppm_lowpc + image->pi_vaddr - 388 image->pi_start; 389 pc -= loadaddress; 390 391 if ((sym = pmcstat_symbol_search(image, pc)) != NULL) 392 pc = sym->ps_start; 393 394 child = pmcstat_cgnode_find(parent, image, pc); 395 child->pcg_count++; 396 } 397} 398 399/* 400 * Printing a callgraph for a PMC. 401 */ 402static void 403pmcstat_callgraph_print_for_pmcid(struct pmcstat_pmcrecord *pmcr) 404{ 405 int n, nentries; 406 uint32_t nsamples; 407 pmc_id_t pmcid; 408 struct pmcstat_cgnode **sortbuffer, **cgn; 409 struct pmcstat_cgnode_hash *pch; 410 411 /* 412 * We pull out all callgraph nodes in the top-level hash table 413 * with a matching PMC id. We then sort these based on the 414 * frequency of occurrence. Each callgraph node is then 415 * printed. 416 */ 417 418 nsamples = 0; 419 pmcid = pmcr->pr_pmcid; 420 if ((sortbuffer = (struct pmcstat_cgnode **) 421 malloc(sizeof(struct pmcstat_cgnode *) * 422 pmcstat_cgnode_hash_count)) == NULL) 423 err(EX_OSERR, "ERROR: Cannot sort callgraph"); 424 cgn = sortbuffer; 425 426 for (n = 0; n < PMCSTAT_NHASH; n++) 427 LIST_FOREACH(pch, &pmcstat_cgnode_hash[n], pch_next) 428 if (pch->pch_pmcid == pmcid) { 429 nsamples += pch->pch_cgnode->pcg_count; 430 *cgn++ = pch->pch_cgnode; 431 } 432 433 nentries = cgn - sortbuffer; 434 assert(nentries <= pmcstat_cgnode_hash_count); 435 436 if (nentries == 0) { 437 free(sortbuffer); 438 return; 439 } 440 441 qsort(sortbuffer, nentries, sizeof(struct pmcstat_cgnode *), 442 pmcstat_cgnode_compare); 443 444 (void) fprintf(args.pa_graphfile, 445 "@ %s [%u samples]\n\n", 446 pmcstat_string_unintern(pmcr->pr_pmcname), 447 nsamples); 448 449 for (cgn = sortbuffer, n = 0; n < nentries; n++, cgn++) { 450 pmcstat_previous_filename_printed = NULL; 451 pmcstat_cgnode_print(*cgn, 0, nsamples); 452 (void) fprintf(args.pa_graphfile, "\n"); 453 } 454 455 free(sortbuffer); 456} 457 458/* 459 * Print out callgraphs. 460 */ 461 462static void 463pmcstat_callgraph_print(void) 464{ 465 struct pmcstat_pmcrecord *pmcr; 466 467 LIST_FOREACH(pmcr, &pmcstat_pmcs, pr_next) 468 pmcstat_callgraph_print_for_pmcid(pmcr); 469} 470 471static void 472pmcstat_cgnode_topprint(struct pmcstat_cgnode *cg, 473 int depth, uint32_t nsamples) 474{ 475 int v_attrs, vs_len, ns_len, width, len, n, nchildren; 476 float v; 477 char ns[30], vs[10]; 478 struct pmcstat_symbol *sym; 479 struct pmcstat_cgnode **sortbuffer, **cgn, *pcg; 480 481 (void) depth; 482 483 /* Format value. */ 484 v = PMCPL_CG_COUNTP(cg); 485 snprintf(vs, sizeof(vs), "%.1f", v); 486 v_attrs = PMCSTAT_ATTRPERCENT(v); 487 488 /* Format name. */ 489 sym = pmcstat_symbol_search(cg->pcg_image, cg->pcg_func); 490 if (sym != NULL) { 491 snprintf(ns, sizeof(ns), "%s", 492 pmcstat_string_unintern(sym->ps_name)); 493 } else 494 snprintf(ns, sizeof(ns), "%p", 495 (void *)cg->pcg_func); 496 497 PMCSTAT_ATTRON(v_attrs); 498 PMCSTAT_PRINTW("%5.5s", vs); 499 PMCSTAT_ATTROFF(v_attrs); 500 PMCSTAT_PRINTW(" %-10.10s %-20.20s", 501 pmcstat_string_unintern(cg->pcg_image->pi_name), 502 ns); 503 504 nchildren = cg->pcg_nchildren; 505 if (nchildren == 0) { 506 PMCSTAT_PRINTW("\n"); 507 return; 508 } 509 510 width = pmcstat_displaywidth - 40; 511 512 if ((sortbuffer = (struct pmcstat_cgnode **) 513 malloc(sizeof(struct pmcstat_cgnode *) * 514 nchildren)) == NULL) 515 err(EX_OSERR, "ERROR: Cannot print callgraph"); 516 cgn = sortbuffer; 517 518 LIST_FOREACH(pcg, &cg->pcg_children, pcg_sibling) 519 *cgn++ = pcg; 520 521 assert(cgn - sortbuffer == (int)nchildren); 522 523 qsort(sortbuffer, nchildren, sizeof(struct pmcstat_cgnode *), 524 pmcstat_cgnode_compare); 525 526 /* Count how many callers. */ 527 for (cgn = sortbuffer, n = 0; n < nchildren; n++, cgn++) { 528 pcg = *cgn; 529 530 v = PMCPL_CG_COUNTP(pcg); 531 if (v < pmcstat_threshold) 532 break; 533 } 534 nchildren = n; 535 536 for (cgn = sortbuffer, n = 0; n < nchildren; n++, cgn++) { 537 pcg = *cgn; 538 539 /* Format value. */ 540 if (nchildren > 1) { 541 v = PMCPL_CG_COUNTP(pcg); 542 vs_len = snprintf(vs, sizeof(vs), ":%.1f", v); 543 v_attrs = PMCSTAT_ATTRPERCENT(v); 544 } else 545 vs_len = 0; 546 547 /* Format name. */ 548 sym = pmcstat_symbol_search(pcg->pcg_image, pcg->pcg_func); 549 if (sym != NULL) { 550 ns_len = snprintf(ns, sizeof(ns), "%s", 551 pmcstat_string_unintern(sym->ps_name)); 552 } else 553 ns_len = snprintf(ns, sizeof(ns), "%p", 554 (void *)pcg->pcg_func); 555 556 len = ns_len + vs_len + 1; 557 if (width - len < 0) { 558 PMCSTAT_PRINTW(" ..."); 559 break; 560 } 561 width -= len; 562 563 PMCSTAT_PRINTW(" %s", ns); 564 if (nchildren > 1) { 565 PMCSTAT_ATTRON(v_attrs); 566 PMCSTAT_PRINTW("%s", vs); 567 PMCSTAT_ATTROFF(v_attrs); 568 } 569 } 570 PMCSTAT_PRINTW("\n"); 571 free(sortbuffer); 572} 573 574/* 575 * Top mode display. 576 */ 577 578void 579pmcpl_cg_topdisplay(void) 580{ 581 int n, nentries; 582 uint32_t nsamples; 583 struct pmcstat_cgnode **sortbuffer, **cgn; 584 struct pmcstat_cgnode_hash *pch; 585 struct pmcstat_pmcrecord *pmcr; 586 587 pmcr = pmcstat_pmcindex_to_pmcr(pmcstat_pmcinfilter); 588 if (!pmcr) 589 err(EX_SOFTWARE, "ERROR: invalid pmcindex"); 590 591 /* 592 * We pull out all callgraph nodes in the top-level hash table 593 * with a matching PMC index. We then sort these based on the 594 * frequency of occurrence. Each callgraph node is then 595 * printed. 596 */ 597 598 nsamples = 0; 599 600 if ((sortbuffer = (struct pmcstat_cgnode **) 601 malloc(sizeof(struct pmcstat_cgnode *) * 602 pmcstat_cgnode_hash_count)) == NULL) 603 err(EX_OSERR, "ERROR: Cannot sort callgraph"); 604 cgn = sortbuffer; 605 606 for (n = 0; n < PMCSTAT_NHASH; n++) 607 LIST_FOREACH(pch, &pmcstat_cgnode_hash[n], pch_next) 608 if (pmcr == NULL || pch->pch_pmcid == pmcr->pr_pmcid) { 609 nsamples += pch->pch_cgnode->pcg_count; 610 *cgn++ = pch->pch_cgnode; 611 } 612 613 nentries = cgn - sortbuffer; 614 assert(nentries <= pmcstat_cgnode_hash_count); 615 616 if (nentries == 0) { 617 free(sortbuffer); 618 return; 619 } 620 621 qsort(sortbuffer, nentries, sizeof(struct pmcstat_cgnode *), 622 pmcstat_cgnode_compare); 623 624 PMCSTAT_PRINTW("%5.5s %-10.10s %-20.20s %s\n", 625 "%SAMP", "IMAGE", "FUNCTION", "CALLERS"); 626 627 nentries = min(pmcstat_displayheight - 2, nentries); 628 629 for (cgn = sortbuffer, n = 0; n < nentries; n++, cgn++) { 630 if (PMCPL_CG_COUNTP(*cgn) < pmcstat_threshold) 631 break; 632 pmcstat_cgnode_topprint(*cgn, 0, nsamples); 633 } 634 635 free(sortbuffer); 636} 637 638/* 639 * Handle top mode keypress. 640 */ 641 642int 643pmcpl_cg_topkeypress(int c, WINDOW *w) 644{ 645 646 (void) c; (void) w; 647 648 return 0; 649} 650 651int 652pmcpl_cg_init(void) 653{ 654 int i; 655 656 pmcstat_cgnode_hash_count = 0; 657 pmcstat_previous_filename_printed = NULL; 658 659 for (i = 0; i < PMCSTAT_NHASH; i++) { 660 LIST_INIT(&pmcstat_cgnode_hash[i]); 661 } 662 663 return (0); 664} 665 666void 667pmcpl_cg_shutdown(FILE *mf) 668{ 669 int i; 670 struct pmcstat_cgnode_hash *pch, *pchtmp; 671 672 (void) mf; 673 674 if (args.pa_flags & FLAG_DO_CALLGRAPHS) 675 pmcstat_callgraph_print(); 676 677 /* 678 * Free memory. 679 */ 680 for (i = 0; i < PMCSTAT_NHASH; i++) { 681 LIST_FOREACH_SAFE(pch, &pmcstat_cgnode_hash[i], pch_next, 682 pchtmp) { 683 pmcstat_cgnode_free(pch->pch_cgnode); 684 LIST_REMOVE(pch, pch_next); 685 free(pch); 686 } 687 } 688} 689 690